Why my codes are not declared?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Madgame
    New Member
    • Jul 2006
    • 4

    Why my codes are not declared?

    it say txtPassword not declared, fromMain not declared, frmLogIn not declared,etc
    there are my code -


    Private Sub cmdEnter_Click( )
    If txtPassword = "lavender" Then
    MsgBox "Welcome to Lavender Book Rental system", vbvOkOnly + vbInformation, "Welcome"
    frmMain.Show
    frmLogIn.Hide
    txtPassword = ""
    Else
    MsgBox "Please enter the correct password", vbOKOnly + vbExclamation, "Sorry!"
    txtPassword = ""
    txtPassword.Set Focus
    End If
    End Sub

    Private Sub Form_Load()
    lblDateToday = Format(Now, "dddd, dd mmmm yyyy")
    lblTime = Format(Now, "hh:mm")
    End Sub
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Hi there,

    are you using the "Option Explicit" keyword along your coding? remember.. using option explicit will require you to declare every variable used with the proper data type assignment..

    please refer to the changes below..
    Code:
    Private Sub cmdEnter_Click()
      If txtPassword.Text = "lavender" Then
        MsgBox "Welcome to Lavender Book Rental system", vbvOkOnly +   vbInformation, "Welcome"
        frmMain.Show
        frmLogIn.Hide
        txtPassword.Text = ""
      Else
        MsgBox "Please enter the correct password", vbOKOnly +   vbExclamation, "Sorry!"
         txtPassword.Text = ""
         txtPassword.SetFocus
      End If
    End Sub
    
    Private Sub Form_Load()
      lblDateToday.Caption = Format(Now, "dddd, dd mmmm yyyy")
      lblTime.Caption = Format(Now, "hh:mm")
    End Sub

    Comment

    • Madgame
      New Member
      • Jul 2006
      • 4

      #3
      i try with the codes you have changed still give me the same erroe message not declared. i am using Microsoft Visual Basic 2005 express edition. how to not use "Option Explicit"?

      Comment

      • BSOB
        New Member
        • Jul 2006
        • 77

        #4
        tools/options/editor/require variable declarataion

        Comment

        Working...