-
Oct 22nd, 2003, 11:52 AM
#1
keeping variables while changing forms [resolved]
Ok, well, I've got a program that allows a user to login, and if the user puts in the corresponding password, it will make the current form invisible, and make a new form visible. I want to be able to move the variable "username" and "password" from Form1 (the login screen) to Form2 (the logged in screen). Is there any way to do it?
Here's some of my code, and where I think I would have to put anything that would be going to the other form..
VB Code:
Private Sub cmd_login_Click()
Dim check As String, loggedin As Boolean
inUser = txt_user.Text
inPass = txt_pass.Text
'username is case insensitive, convert it to lower case
inUser = LCase(inUser)
'get rid of unwanted characters in username and password
inUser = safeStr(inUser)
inPass = safeStr(inPass)
'open user file and check validility of password
check = OpenFile(pathUsers & inUser & pathType)
If check = inPass Then
loggedin = True
Else
loggedin = False
End If
If loggedin = True Then
'get rid of login screen
Form1.Visible = False
'show logged in screen
Form2.Visible = True
End If
End Sub
Thanks for any help.
edit: I think this might be a really simple question to answer, but I'm not really sure.. I'm fairly new to VB, and so I don't know everything about it.
Last edited by kows; Oct 22nd, 2003 at 09:31 PM.
-
Oct 22nd, 2003, 12:19 PM
#2
PowerPoster
forms are objects, so you can get at their variables by referencing them as
form1.var1
alternatively, you could just make the variables global by putting them in a non-form module and declaring them public
-
Oct 22nd, 2003, 02:23 PM
#3
I was looking at your code, and it's a small thing but you would be better off doing
VB Code:
If loggedin = True Then
'get rid of login screen
Form2.Visible = True
'show logged in screen
Form1.Visible = False
End If
That way the user who has a slow computer doesn't momentarily see a blank screen between the hiding of Form1 and the showing of Form2.
-
Oct 22nd, 2003, 09:29 PM
#4
yeah I saw the same thing and even noticed it when I was making it, and I'll probably change it as soon as I can.. anyways, thanks guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|