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 Function MyFunction1(a As String, b As Object) As Double ' Lot of things going on here End Function Function MyFunction2(c As Integer, d as Variant) As Object ' Lot of things going on here End Function Function MyFunction3(e As Boolean) As Boolean ' Some things going on here End Function </CODE> Now, let's say that I created a dialogue with three buttons. One of those buttons calls MySub1, another will call MySub2 and the third will call MySub3. The functions are maybe used within one or more of those subroutines, but that does probably not matter. Now, when clicking, let's say, button 2, I get an error message telling me that one of the global variables doesn't exist or isn't declared. How can this happen? So my questions are: No matter which one of all the subroutines in a module that I run, can I count on that my global variables exists and that they remember their values from time to time? Do I also need to declare my variables within each subroutine that is using them, using the Dim statement? Well, something like that… I'll give you an example: I created a search dialogue that fulfills my needs in a specific spreadsheet (everything is preset the only way that makes sense in that particular spreadsheet - that's my main point by creating such a thing in the first place). It has three buttons and a text field. In the text field I type what I want to search for, of course. The buttons are: Find First, Find Previous and Find Next. 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. So the modell for doing this is the ”code” above, kind of. Should that work properly? If not, what am I doing wrong? Johnny Rosenberg --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
