2009/7/17 Bernard Marcelly <[email protected]>: > Hi Johnny, > Message de Johnny Rosenberg date 2009-07-17 18:21 : >> >> As I understand it, global variables should be declared first of all, >> before all subroutines and functions in a module, right? >> >> Like this: <CODE> >> >> Option explicit >> >> Global x As Long, y As Object, z As Variant, k As String >> >> Sub MySub1 >> ' Lot of things going on here >> End Sub >> >> Sub MySub2 >> ' Lot of things going on here >> End Sub >> >> Sub MySub3 >> ' Lot of things going on here >> End Sub >> > > Correct. But what's inside the Sub is important ! > When my code does not work, I suspect my code first. > > I verified with a simple code : > > Sub MySubB1 > x = x+1 > MsgBox x > End Sub > > > Sub MySubB2 > z = z +3.5 > MsgBox z > End Sub > > Sub MySubB3 > k = k & "A" > MsgBox k > End Sub > > And, of course, it works as expected. Same with an object variable. > >> So, it's obvious that I need at least the search descriptor to be a >> global variable, because when I search for the first time the >> descriptor is created and when I want to search for the next occurance >> I need to use the same descriptor again making sure that I really find >> the NEXT occurance each time, not the same one. > > Make sure that you first assign a search descriptor to your Object variable > before filling one of the descriptor fields. Else the variable will be Null > and you get an error. > >> Do I also need to declare my variables within each subroutine that is >> using them, using the Dim statement? > > Certainly not. This would create a local variable which would hide the > global one inside the Sub. > > Regards > Bernard
Thanks, both of you. I guess I have to do further debugging of my code, then. I'll be back if necessary… Johnny Rosenberg --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
