visual_star

Howdy

I have about 5 to 10 subroutines and the program can use up to 5 subs at a time

for example

its a hockey simulator program so its starts with a faceoff routine and depending on what team wins the faceoff it can go to two seperate subs

so after i click a button it goes like this

Opening_faceoff()

runs code

Left_defense_Home()

runs code

if a player gets a shot i have 3 seperate shot subs (i.e. rwer, lwer, center)

LeftH_shot()

runs code

if save

Defensive_Away_Zone_faceoff()

away wins

Defensive_Away_Zone_RD

i think you get the idea, I tryed to count the plays by the following code everytime there is a faceoff

play = play + 1

and after the shot routines to stop the subroutines by this code

If play = 2 Then

Exit Sub

End If

assuming there could be any number of subroutines running not sure this would work

also i have a number of random number generations like the following that seem to get the program hung up on:

random_num = random.Next(1, 3)

not sure what to do

Nick



Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

js06

Could you post your code to get a better picture of what you are doing with it






Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

visual_star

Its quite long but here it is:

the faceoff sub is longer but this gives u an idea

I also have many other subroutines

Private Sub Away_Defensive_Faceoff()

faceoff_home_win = False

faceoff_away_win = False

If center1_fo_home = 9 And center1_fo_away = 8 Then

If num_array(1) > 43 Then

faceoff_home_win = True

center1_home_taken = center1_home_taken + 1

center1_home_won = center1_home_won + 1

center1_away_taken = center1_away_taken + 1

ElseIf num_array(1) <= 43 Then

faceoff_away_win = True

center1_away_taken = center1_away_taken + 1

center1_away_won = center1_away_won + 1

center1_home_taken = center1_home_taken + 1

End If

.......

If faceoff_home_win = True And face_array(1) > 50 Then

RDH_Shot()

play = play + 1

ElseIf faceoff_home_win = True And face_array(1) <= 50 Then

LDH_Shot()

play = play + 1

ElseIf faceoff_away_win = True Then

Defense_Away_Zone_RD()

play = play + 1

End If

Private Sub Defense_Away_Zone_RD()

Dim rdSkate As Boolean = False

Dim ld_pos_L As Boolean = False

Dim rd_takes_shot As Boolean = False

Dim ld_open As Boolean = False

Dim ld_takes_shot As Boolean = False

Dim rwerSkate As Boolean = False

Dim rwerStick As Boolean = False

Dim rwerQuick As Boolean = False

Dim rwerskates As Boolean = False

Dim rwer_passto_center As Boolean = False

Dim rwer_pass_rd As Boolean = False

Dim rwer_pass_center As Boolean = False

Dim rwer_open As Boolean = False

Dim rwer_takes_shot As Boolean = False

Dim rwer_pass_lwer As Boolean = False

Dim center_open As Boolean = False

Dim center_pass_rwer As Boolean = False

Dim center_takes_shot As Boolean = False

Dim centerQuick As Boolean = False

Dim centerSkate As Boolean = False

Dim centerStick As Boolean = False

Dim lwer_open As Boolean = False

Dim lwer_pass_center As Boolean = False

Dim lwer_pass_ld As Boolean = False

Dim lwer_pass_rwer As Boolean = False

Dim lwer_takes_shot As Boolean = False

Dim rdpassto As New Random

Dim centerpass As New Random

Dim rdpass As Integer

Dim ldpass As Integer

Dim pass_D As Integer

rdpass = rdpassto.Next(1, 6)

ldpass = Int((6 * Rnd()) + 1)

pass_D = centerpass.Next(1, 100)

If rd1_pa_away > lwer1_po_home Then

rwer_open = True

ElseIf rd1_pa_away > rwer1_po_home Then

ld_open = True

ElseIf rwer_open = False And ld_open = False Then

rdSkate = True

End If

If rwer_open = True And rwer1_qk_away > lwer1_qk_home Then

rwerQuick = True

ElseIf rwer_open = True And rwer1_pc_away > lwer1_ck_home Then

rwerStick = True

ElseIf rwer_open = True And rwer1_sk_away > lwer1_sk_home Then

rwerSkate = True

ElseIf rwer_open = True And rwer1_pa_away > lwer1_po_home Then

rwer_pass_center = True

End If

If rwerQuick = True Or rwerStick = True Or rwerSkate = True And rwer1_pa_away > center1_po_home Then

center_open = True

ElseIf rwerQuick = True Or rwerStick = True Or rwerSkate = True And rwer1_pa_away > rd1_po_home Then

lwer_open = True

ElseIf rwerQuick = True Or rwerStick = True Or rwerSkate = True And center_open = False Then

rwerskates = True

End If

If rwer_pass_center = True Or center_open = True And center1_pa_away > rd1_po_home Then

lwer_open = True

ElseIf rwer_pass_center = True Or center_open = True And center1_qk_away > ld1_qk_home Then

centerQuick = True

ElseIf rwer_pass_center = True Or center_open = True And center1_sk_away > ld1_sk_home Then

centerSkate = True

ElseIf rwer_pass_center = True Or center_open = True And center1_pc_away > ld1_sk_home Then

centerStick = True

ElseIf rwer_pass_center = True Or center_open = True And center1_qk_away > rd1_qk_home Then

centerQuick = True

ElseIf rwer_pass_center = True Or center_open = True And center1_sk_away > rd1_sk_home Then

centerSkate = True

ElseIf rwer_pass_center = True Or center_open = True And center1_pc_away > rd1_sk_home Then

centerStick = True

ElseIf lwer_open = False And centerSkate = False And centerStick = False And centerQuick = False Then

center_pass_rwer = True

End If

If rwerskates = True Or center_pass_rwer = True And rwer1_pa_away > rd1_po_home Then

rwer_pass_lwer = True

ElseIf rwerskates = True Or center_pass_rwer = True And rwer1_pa_away > ld1_po_home Then

rwer_passto_center = True

ElseIf rwerskates = True Or center_pass_rwer = True And rd1_sh_away > rwer1_sh_away Then

rwer_pass_rd = True

ElseIf rwerskates = True Or center_pass_rwer = True And rwer_pass_lwer = False And rwer_passto_center = False And rwer_pass_rd = False Then

rwer_takes_shot = True

RwerA_Shot()

End If

If lwer_open = True And lwer1_pa_away > ld1_po_home Then

lwer_pass_rwer = True

ElseIf lwer_open = True And lwer1_pa_away > rd1_po_home Then

lwer_pass_center = True

ElseIf lwer_open = True And ld1_sh_away > lwer1_sh_away Then

lwer_pass_ld = True

ElseIf lwer_open = True And lwer_pass_rwer = False And lwer_pass_center = False And lwer_pass_ld = False Then

lwer_takes_shot = True

LwerA_Shot()

End If

If centerQuick = True Or centerSkate = True Or centerStick = True And center1_sh_away < rwer1_sh_away Then

rwer_takes_shot = True

RwerA_Shot()

ElseIf centerQuick = True Or centerSkate = True Or centerStick = True And center1_sh_away < lwer1_sh_away Then

lwer_takes_shot = True

LwerA_Shot()

ElseIf centerQuick = True Or centerSkate = True Or centerStick = True And center1_sh_away >= lwer1_sh_away Then

center_takes_shot = True

centerA_Shot()

ElseIf centerQuick = True Or centerSkate = True Or centerStick = True And center1_sh_away >= rwer1_sh_away Then

center_takes_shot = True

centerA_Shot()

End If

If rwer_pass_lwer = True Then

lwer_takes_shot = True

LwerA_Shot()

End If

If lwer_pass_rwer = True Then

rwer_takes_shot = True

RwerA_Shot()

End If

If rwer_passto_center = True Or lwer_pass_center = True Then

center_takes_shot = True

centerA_Shot()

End If

If rwer_pass_rd = True Then

rd_takes_shot = True

RDA_Shot()

End If

If lwer_pass_ld = True Then

ld_takes_shot = True

LDA_Shot()

End If

End Sub

Goes to centerA_shot Sub

and at the end it goes back to a faceoff

If play = 2 Then

Text_Write()

End If

If rwer_goal = True Or lwer_goal = True Or center_goal = True Then

Opening_Faceoff()

ElseIf rwer_goal = False Or lwer_goal = False Or center_goal = False Then

Home_Defensive_Faceoff()

End If

creates an infinite loop and i'm not sure how to end the code or subroutine





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

visual_star

Its quite long but here it is:

the faceoff sub is longer but this gives u an idea

I also have many other subroutines

Private Sub Away_Defensive_Faceoff()

faceoff_home_win = False

faceoff_away_win = False

If center1_fo_home = 9 And center1_fo_away = 8 Then

If num_array(1) > 43 Then

faceoff_home_win = True

center1_home_taken = center1_home_taken + 1

center1_home_won = center1_home_won + 1

center1_away_taken = center1_away_taken + 1

ElseIf num_array(1) <= 43 Then

faceoff_away_win = True

center1_away_taken = center1_away_taken + 1

center1_away_won = center1_away_won + 1

center1_home_taken = center1_home_taken + 1

End If

.......

If faceoff_home_win = True And face_array(1) > 50 Then

RDH_Shot()

play = play + 1

ElseIf faceoff_home_win = True And face_array(1) <= 50 Then

LDH_Shot()

play = play + 1

ElseIf faceoff_away_win = True Then

Defense_Away_Zone_RD()

play = play + 1

End If

Private Sub Defense_Away_Zone_RD()

Dim rdSkate As Boolean = False

Dim ld_pos_L As Boolean = False

Dim rd_takes_shot As Boolean = False

Dim ld_open As Boolean = False

Dim ld_takes_shot As Boolean = False

Dim rwerSkate As Boolean = False

Dim rwerStick As Boolean = False

Dim rwerQuick As Boolean = False

Dim rwerskates As Boolean = False

Dim rwer_passto_center As Boolean = False

Dim rwer_pass_rd As Boolean = False

Dim rwer_pass_center As Boolean = False

Dim rwer_open As Boolean = False

Dim rwer_takes_shot As Boolean = False

Dim rwer_pass_lwer As Boolean = False

Dim center_open As Boolean = False

Dim center_pass_rwer As Boolean = False

Dim center_takes_shot As Boolean = False

Dim centerQuick As Boolean = False

Dim centerSkate As Boolean = False

Dim centerStick As Boolean = False

Dim lwer_open As Boolean = False

Dim lwer_pass_center As Boolean = False

Dim lwer_pass_ld As Boolean = False

Dim lwer_pass_rwer As Boolean = False

Dim lwer_takes_shot As Boolean = False

Dim rdpassto As New Random

Dim centerpass As New Random

Dim rdpass As Integer

Dim ldpass As Integer

Dim pass_D As Integer

rdpass = rdpassto.Next(1, 6)

ldpass = Int((6 * Rnd()) + 1)

pass_D = centerpass.Next(1, 100)

If rd1_pa_away > lwer1_po_home Then

rwer_open = True

ElseIf rd1_pa_away > rwer1_po_home Then

ld_open = True

ElseIf rwer_open = False And ld_open = False Then

rdSkate = True

End If

If rwer_open = True And rwer1_qk_away > lwer1_qk_home Then

rwerQuick = True

ElseIf rwer_open = True And rwer1_pc_away > lwer1_ck_home Then

rwerStick = True

ElseIf rwer_open = True And rwer1_sk_away > lwer1_sk_home Then

rwerSkate = True

ElseIf rwer_open = True And rwer1_pa_away > lwer1_po_home Then

rwer_pass_center = True

End If

If rwerQuick = True Or rwerStick = True Or rwerSkate = True And rwer1_pa_away > center1_po_home Then

center_open = True

ElseIf rwerQuick = True Or rwerStick = True Or rwerSkate = True And rwer1_pa_away > rd1_po_home Then

lwer_open = True

ElseIf rwerQuick = True Or rwerStick = True Or rwerSkate = True And center_open = False Then

rwerskates = True

End If

If rwer_pass_center = True Or center_open = True And center1_pa_away > rd1_po_home Then

lwer_open = True

ElseIf rwer_pass_center = True Or center_open = True And center1_qk_away > ld1_qk_home Then

centerQuick = True

ElseIf rwer_pass_center = True Or center_open = True And center1_sk_away > ld1_sk_home Then

centerSkate = True

ElseIf rwer_pass_center = True Or center_open = True And center1_pc_away > ld1_sk_home Then

centerStick = True

ElseIf rwer_pass_center = True Or center_open = True And center1_qk_away > rd1_qk_home Then

centerQuick = True

ElseIf rwer_pass_center = True Or center_open = True And center1_sk_away > rd1_sk_home Then

centerSkate = True

ElseIf rwer_pass_center = True Or center_open = True And center1_pc_away > rd1_sk_home Then

centerStick = True

ElseIf lwer_open = False And centerSkate = False And centerStick = False And centerQuick = False Then

center_pass_rwer = True

End If

If rwerskates = True Or center_pass_rwer = True And rwer1_pa_away > rd1_po_home Then

rwer_pass_lwer = True

ElseIf rwerskates = True Or center_pass_rwer = True And rwer1_pa_away > ld1_po_home Then

rwer_passto_center = True

ElseIf rwerskates = True Or center_pass_rwer = True And rd1_sh_away > rwer1_sh_away Then

rwer_pass_rd = True

ElseIf rwerskates = True Or center_pass_rwer = True And rwer_pass_lwer = False And rwer_passto_center = False And rwer_pass_rd = False Then

rwer_takes_shot = True

RwerA_Shot()

End If

If lwer_open = True And lwer1_pa_away > ld1_po_home Then

lwer_pass_rwer = True

ElseIf lwer_open = True And lwer1_pa_away > rd1_po_home Then

lwer_pass_center = True

ElseIf lwer_open = True And ld1_sh_away > lwer1_sh_away Then

lwer_pass_ld = True

ElseIf lwer_open = True And lwer_pass_rwer = False And lwer_pass_center = False And lwer_pass_ld = False Then

lwer_takes_shot = True

LwerA_Shot()

End If

If centerQuick = True Or centerSkate = True Or centerStick = True And center1_sh_away < rwer1_sh_away Then

rwer_takes_shot = True

RwerA_Shot()

ElseIf centerQuick = True Or centerSkate = True Or centerStick = True And center1_sh_away < lwer1_sh_away Then

lwer_takes_shot = True

LwerA_Shot()

ElseIf centerQuick = True Or centerSkate = True Or centerStick = True And center1_sh_away >= lwer1_sh_away Then

center_takes_shot = True

centerA_Shot()

ElseIf centerQuick = True Or centerSkate = True Or centerStick = True And center1_sh_away >= rwer1_sh_away Then

center_takes_shot = True

centerA_Shot()

End If

If rwer_pass_lwer = True Then

lwer_takes_shot = True

LwerA_Shot()

End If

If lwer_pass_rwer = True Then

rwer_takes_shot = True

RwerA_Shot()

End If

If rwer_passto_center = True Or lwer_pass_center = True Then

center_takes_shot = True

centerA_Shot()

End If

If rwer_pass_rd = True Then

rd_takes_shot = True

RDA_Shot()

End If

If lwer_pass_ld = True Then

ld_takes_shot = True

LDA_Shot()

End If

End Sub

Goes to centerA_shot Sub

and at the end it goes back to a faceoff

If play = 2 Then

Text_Write()

End If

If rwer_goal = True Or lwer_goal = True Or center_goal = True Then

Opening_Faceoff()

ElseIf rwer_goal = False Or lwer_goal = False Or center_goal = False Then

Home_Defensive_Faceoff()

End If

creates an infinite loop and i'm not sure how to end the code or subroutine





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

js06

That is a lot to take in

Dave299 probably can give some good help on this one

If you don't get anything better this will help you out

What i have done recently to a project of mine that called a lot of subs in a loop was to wrap all the subs into one if then else statement and the second thing was to wrap it all into a timer tick event

Here is a link to the thread i posted a while back explaining the whole thing

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1953703&SiteID=1

It is a lot of information but if you read through it will make sense






Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

visual_star

Uhm what does the endgame() sub look like

I actually need to somehow incorporate a timer so i can determine the time when a goal is scored so that might work for me

but the timer would have to continue through out the running of code. not sure how to do that with the example i read

any ideas

so basically the code would have to return to the beginning of code every loop not sure i understand that part

The other question i guess is why u needed 3 or 4 different tick events

and if i have up to 10 different subs where do i return to after they are used

any help would be great





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

js06

Ok, the 4 timers was just an example of using multiple timers to run multiple instances of a loop that would normally cause an overflow exception or system lockup

You don't neccessarily need 4 timers for yours

I actually only used 1 timer in my actual program

The 5th post in my thread is the main one with the code that i used

the others were just for examples

The endgame sub is just a sub that i used to show a form with the score and some other related info

And i also used it to reset variables that would be needed to run a new game

I will have to get back to you on the rest when i get back home from an appointment

Take a look at the 5th post in my thread again and read the commented notes

they should help a little






Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

Dave299

I think we are in danger of not seeing the wood for the trees here.

visual_star - could you go through your code and just post the relevant bits showing where a sub is called from another sub and why. Do this for all the subs and then maybe we will have some chance of seeing where the problem is.





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

visual_star

Firstly we start the game by clicking a button

then it loads the various player attributes

then it goes to this sub

Public Sub Opening_Faceoff()

faceoff_home_win = False

faceoff_away_win = False

If center1_fo_home = 9 And center1_fo_away = 8 Then

If num_array(0) > 43 Then

faceoff_home_win = True

center1_home_taken = center1_home_taken + 1

center1_home_won = center1_home_won + 1

center1_away_taken = center1_away_taken + 1

ElseIf num_array(0) <= 43 Then

faceoff_away_win = True

center1_away_taken = center1_away_taken + 1

center1_away_won = center1_away_won + 1

center1_home_taken = center1_home_taken + 1

End If

decides who won the faceoff

If faceoff_home_win = True And face_array(0) > 50 Then

Left_Defense_home()

play = play + 1

ElseIf faceoff_home_win = True And face_array(0) <= 50 Then

Right_Defense_home()

play = play + 1

ElseIf faceoff_away_win = True And face_array(0) > 50 Then

Left_Defense_away()

play = play + 1

ElseIf faceoff_away_win = True And face_array(0) <= 50 Then

Right_Defense_away()

play = play + 1

End If

decides which subroutine to run - These four subs run and determines which player has the puck and goes to a shooting sub routine

at the end of the shooting subroutine the following code decides which type of faceoff to go to next:

If rwer_goal = True Or lwer_goal = True Or center_goal = True And play = 1 Then

Opening_Faceoff()

ElseIf rwer_goal = False Or lwer_goal = False Or center_goal = False And play = 1 Then

Away_Defensive_Faceoff()

Else

Stop

End If

Private Sub Away_Defensive_Faceoff()

faceoff_home_win = False

faceoff_away_win = False

If center1_fo_home = 9 And center1_fo_away = 8 Then

If num_array(1) > 43 Then

faceoff_home_win = True

center1_home_taken = center1_home_taken + 1

center1_home_won = center1_home_won + 1

center1_away_taken = center1_away_taken + 1

ElseIf num_array(1) <= 43 Then

faceoff_away_win = True

center1_away_taken = center1_away_taken + 1

center1_away_won = center1_away_won + 1

center1_home_taken = center1_home_taken + 1

End If

At the end of this faceoff it decides which player it goes to next

If faceoff_away_win = True And face_array(1) > 50 Then

RDA_Shot()

play = play + 1

ElseIf faceoff_away_win = True And face_array(1) <= 50 Then

LDA_Shot()

play = play + 1

ElseIf faceoff_home_win = True Then

Defense_Home_Zone_RD()

play = play + 1

End If

From here it goes to a few more subroutines - but basically if a goal is scored it goes to opening faceoff, If no goal is scored it goes to another faceoff and so on

as i stated before i tried to count the number of plays but i think it gets hung up before play 2 is finished

i use the same variable names for all shooting sub routines - might be the cause of it but i'm not sure

I think its getting hung up on a few New Random generators

cause it goes to Opening_faceoff and then through Left_Defense_Home / Right_Defense_Home and goes to Away_Defensive_Faceoff() and then goes to RDH_shot and gets hung up on the following variable:

Dim rebounds As New Random

Thats where the error stops the program





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

Dave299

OK - That's a bit clearer.

It's late over here so I'm just off to bed but I'll have a look in the morning if no-one else deals with it before then





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

js06

visual_star,

I am going to wait and let dave see what he can tell you about this one

He seems to have a way with these things that i don't fully understand yet

Arrays and loop elimination is something he understands better than me

And at the moment i am having some brain lock on certain things (overload problem)

If you don't get it worked out then i can give you some more advice on using the timers

I don't get alerts sent to me anymore (for about a month now) so i may lose track of your post

If you need more help on my end later then you are welcome to email me at jeff@txun.net

Just send me a brief email with your thread link and i will try to help you out

Good luck






Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

Dave299

You don't mention what error you get but looking at the code I presume it is a Stack Overflow.

My problem here is that I know nothing about Hockey apart from what I have just gleaned from what you have written above. Still here goes anyway:

The problem is that you are not exiting the subs when you call the next one and the last one calls the first one and you go round in a loop until the stack overflow occurs.

One way round this is to use Functions instead of Subs and to have the decision tree as to what to do next outside of the functions.

Have a look at the following simple example which may give you the general idea. I have defined a number of enumerations which contain the possible outcomes of the various functions. The program just sits in a loop until the FaceOffType is set to None, which can be done in the Shooting function. The DoEvents in the Shooting routine is simply to allow you to stop the program with the X button.

Code Snippet

Public Class Form1

Enum FaceOffTypes

None

Opening

HomeDefensive

AwayDefensive

End Enum

Enum FaceOffResults

Home

Away

End Enum

Enum Players

Player1

Player2

Player3

End Enum

Dim FaceOfftype As FaceOffTypes = FaceOffTypes.Opening

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Do While FaceOfftype <> FaceOffTypes.None

Select Case FaceOfftype

Case FaceOffTypes.Opening

Select Case Opening_Faceoff()

Case FaceOffResults.Home

Select Case Left_Defense_Home()

Case Players.Player1

FaceOfftype = Shooting()

Case Players.Player2

Case Players.Player3

End Select

Case FaceOffResults.Away

End Select

End Select

Loop

End Sub

Private Function Opening_Faceoff() As FaceOffResults

Return FaceOffResults.Home

End Function

Private Function Left_Defense_Home() As Players

Return Players.Player1

End Function

Private Function Shooting() As FaceOffTypes

Application.DoEvents()

Return FaceOffTypes.Opening

End Function

End Class





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

visual_star

Howdy

I haven't used cases much before but from what i can understand basically by using functions and cases the function returns either what faceoff to run and also later on returns what player has the puck at the end of the code and returns to the button click sub to find out what to do next.

The one thing i don't understand is the line

Do While faceofftype <> faceofftype.none

and basically how do we determine there is no faceoff later on in the code

because u can have up to 35 plays

so would u count the plays somehow in the functions and stop it at 35 plays or whatever

like

If play = 4 Then

Return FaceoffTypes.None

ElseIf lwer_goal = True and play = 1 or play = 2 or play = 3 Then

Return FaceoffTypes.Opening

ElseIf lwer_goal = False And play = 1 or play = 2 or play = 3 Then

Return FaceoffTypes.Away

End If

would something like that work

would i have to close the functions before going somewhere else or would that happen automatically once the function returns a value

thanks for your help

Nick





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

Dave299

Hi Nick

Dealing with the last question first - once a function returns it has finished, you don't have to close it - it's as if a sub had reached the End Sub or an Exit Sub.

What you have suggested for ending the game would work fine but you don't have to use the FaceOffType - you could use some other criteria such as the number of plays, e.g.

Dim NoOfPlays As Integer

and control the loop with something like:

Do While NoOfPlays < 35

Until whatever criteria you choose is met the loop, and the game, will continue.

Hope that helps.





Re: Visual Basic Express Edition Infinite Loop - having trouble exiting

ReneeC

This architecture is never going to work. Dave is correct you can't call a subroutine the calls another and then another which calls the calling routine. When you say you have several routines going at the same time you really don't. They are strung out on the stack like a string a of pearls and the stack only has so much room before it over flows.

So What to do I think you need an archirtectural change where, when a subroutine sees that another needs to run that it pushes instructions on a queue and returns. The caller of that routine does not return until the queue is empty.

The queue could be an arraylist functioning as your stack actually

Private CallQueue as New Arraylist ' As a member Variable

So how could you implement such a thing

Start with an arraylist and a structure. The structure might look like this

Public Structure SubCall

Public SubName as String

Public Arg1 as Object

Public Arg2 as Object

Public Arg3 as Object

end Structure

Let's say that Subroutine A decides that it Needs to call Sub Routine B with an argument value of 23

Subroutine A would do this:

Dim a as new SubCall

A.SubName="B"

A.Arg1 = 23

CallQueue.Add(S)

Return

Upon returning the caller does this: (I'm thinking a stack would be Better)

I'm going to break into pseudo so that i do write an operating system....

Dim B as SubCall

While (CallQueue.Count <> o) then

b = CallQueue.Pop

ProcessCall(b)

End While

return ' Game Over

ProcessCall( Call )

SelectCase Call.SubName

Case A

SubA(Call.Arg1)

Case B

SubB(Call.Arg1,Arg2)

'Etc

return

This is basically a smilar architecture to the message pump. And it insures no Snarls and Messy Hair.

Every thing is called by a central dispatcher in an orderly fashion.