Variables that can be accessed by all forms

BlackByte

Well-known member
Joined
Jun 29, 2008
Messages
126
Location
South Africa, Durban
Programming Experience
1-3
Hi i am writing an application that will require users to provide login details. After the user has logd in a second form will be shown. Allowing the user to change his/her own details. What i have a problem is, im not able to pass the variables, containing username and password in the login form to the second form. Ive tried declaring the variables as Public but when the login form closes the variable are reset to zero. Please help..
 
You need to add a new module and declare those variables with the Public keyword instead of Dim.

From the menu bar, click Project and Add Module. Select Module and give it a name if you wish. Then declare your variables with Public. They will now be recognized by all the forms throughout your project.
 
Solved

You need to add a new module and declare those variables with the Public keyword instead of Dim.

From the menu bar, click Project and Add Module. Select Module and give it a name if you wish. Then declare your variables with Public. They will now be recognized by all the forms throughout your project.

Thank you very much, its working okay now.
 
Hi,

Can you tell me how to declare the username in the module as i am new to VB and also having problems doing the same.

Many thanks
 
To declare a global variable in a module form you want to use the Public keyword instead of Dim

Public g_strUserName As String = ""
 
Thanks Tom, i got the following to work. Is it too much text or is it ok?


Module Moduleuser

Public Function VerifyUser(ByVal user As String) As String
user = Loginform.txtusername.Text
Return user
End Function

End Module
 
Wow Im not really sure what your doing there.... It makes no use of a global variable at all. Second your creating a parameter which is going to expect you to actually pass it a value when you call the function but thats not how its being used. And third you shouldnt access control properties from outside of its own form.

Please explain your question better, perhaps I misunderstood your request.
 
Back
Top