Results 1 to 4 of 4

Thread: keeping variables while changing forms [resolved]

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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:
    1. Private Sub cmd_login_Click()
    2.   Dim check As String, loggedin As Boolean
    3.   inUser = txt_user.Text
    4.   inPass = txt_pass.Text
    5.   'username is case insensitive, convert it to lower case
    6.     inUser = LCase(inUser)
    7.   'get rid of unwanted characters in username and password
    8.     inUser = safeStr(inUser)
    9.     inPass = safeStr(inPass)
    10.   'open user file and check validility of password
    11.   check = OpenFile(pathUsers & inUser & pathType)
    12.   If check = inPass Then
    13.     loggedin = True
    14.   Else
    15.     loggedin = False
    16.   End If
    17.   If loggedin = True Then
    18.     'get rid of login screen
    19.       Form1.Visible = False
    20.     'show logged in screen
    21.       Form2.Visible = True
    22.   End If
    23. 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.
    Like Archer? Check out some Sterling Archer quotes.

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    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

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427
    I was looking at your code, and it's a small thing but you would be better off doing

    VB Code:
    1. If loggedin = True Then
    2.     'get rid of login screen
    3.       Form2.Visible = True
    4.     'show logged in screen
    5.       Form1.Visible = False
    6.   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.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    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.
    Like Archer? Check out some Sterling Archer quotes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width