CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Compile error

  1. #1
    Join Date
    Aug 2001
    Location
    MN,USA
    Posts
    5

    Compile error

    My project starts with login form, after the password validation the form1 should be load.

    My question is from the following code the compile error comming.

    Variable not defined.


    Private Sub cmdOK_Click()
    If txtPassword = "password" Then
    LoginSucceeded = True
    Me.Hide
    Load Form1
    Else
    MsgBox "Invalid Password, try again!", , "Login"
    txtPassword.SetFocus
    SendKeys "{Home}+{End}"
    End If
    End Sub

    Please give me some solution

    Sridhar



  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: variable not defined

    This occur when you have a "Option Exlpicit" statement at the beginnig of code and you refer to a variable not defined with
    Dim variable as ... Private variable as... Public variable as...
    in your case:
    LoginSucceeded seems to be the one
    you should have somewhere a
    Dim LoginSucceeded as boolean
    However, I think you need this variable as public:
    Public LoginSucceeded as boolean
    and you could need it on top of code of your form (thus becoming a property of the form) or at top of a Bas module (=satndard module).
    Another chance: does in your projeect exists a Form which is named "Form1"?

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Compile error

    Instead of "Load Form1" try Form1.Show


  4. #4
    Join Date
    Aug 2001
    Location
    MN,USA
    Posts
    5

    Re: variable not defined

    Hi Cimperiali,

    Whatever you said are already there in my login form.

    Give me a more clue please.

    Thanks

    Sridhar


  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: variable not defined

    Does not vb ide highlight the statement which causes the matter?


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: If you are still looking for it


    'you sure the name of the variable LoginSucceeded
    'had two "e" when you dim it?

    private Sub cmdOK_Click()
    If txtPassword = "password" then
    'txtPassword must be the name of a textBox (not an arry of textboxes!).
    'Check for the name to match!

    LoginSucceeded = true 'I copied this, so here may be the mistake: one "e" may
    ' be enough...
    'LoginSucceeded= a boolean maybe pubblic variable

    me.Hide
    'this code is in a form, not in a bas/class module

    Load Form1
    'Form1 must be the name of a form in your project. It should not
    'be the same form where this code is

    else
    MsgBox "Invalid Password, try again!", , "Login"

    txtPassword.SetFocus

    SendKeys "{Home}+{End}"


    End If
    End Sub





    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured