Click to See Complete Forum and Search --> : General Declarations


Starcraft
February 9th, 2000, 11:41 PM
what is the declarations for? i dont get it, i have only read one vb book.

Cakkie
February 10th, 2000, 12:17 AM
The general declaration is used to declare variables who must be accessible from within the form/module it is in(DIM), or withing the entire project(PUBLIC).
Like if you had this code:

'public declarations
Dim s as Integer

public sub Command1_Click()
'button 1 is pressed
t = t + 1
msgbox t
End Sub

public sub Command2_Click()
'button 2 is pressed
s = s + 1
msgbox s
End Sub



This would result in that when you press button 1, 1 is added to T, but because T isn't declared, it's value is cleared whenever the program leaves the sub, in this case after the messagebox. This results in t always being 1 when button 1 is clicked.
However, pressing button 2 will result in 1 being added to s. The value of S will remain the same when the program exits the sub. So when it enters the sub for a second time, it's value will be 2.

Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.