Results 1 to 14 of 14

Thread: Arguement Not Optional?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Arguement Not Optional?

    I'm fairly new to VB and just dug out the old disc so sorry if this is in the wrong place or if it's actually a very simple answer..

    I'm trying to do an extremely simple login form that doesn't use any other database but i wouldnt mind using a text file, at the moment i'm using this code but it's saying arguement not optional whenever i click the button.

    Code:
    'Global Variables
    Dim Username As String                       'Username Variable
    Dim Password As String                       'Password Variable
     
    Private Sub cmdLogin_Click()
     
    Username = "Test"              'What the Username Variable is
    Password = "Test"              'What the Password Variable is
     
    'If Statement Starting Here
    'It States that if the username is = to text box and password is = password text box, then it should login, else display error message!
    If Username = txtUsername And Password = txtPassword Then
     
               frmLoginSuccess.Show    'Shows the Login Success Form
               frmLoginScreen.Hide       'Hides the Login Screen
     
    Else
     
    'A Message box that displays you have entered the wrong username and password
               
        MsgBox ("You have entered the wrong username and password")
     
    End If
     
    End Sub
    I've found the code on the internet...

  2. #2
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: Arguement Not Optional?

    Code:
    MsgBox ("You have entered the wrong username and password")
    
    ->
    
    MsgBox "You have entered the wrong username and password"
    No, that wont do!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: Arguement Not Optional?

    Still the same error, it's highlighting the if statement when it appears...

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Arguement Not Optional?

    Is this VB6 or .Net?

    If .Net, use txtPassword.Text and txtUserName.Text; I've read that you must provide the property names but am unsure

    If VB6, ensure you do not have any control names, function/sub names or form names that use the name Password or UserName.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: Arguement Not Optional?

    Quote Originally Posted by LaVolpe View Post
    Is this VB6 or .Net?

    If .Net, use txtPassword.Text and txtUserName.Text; I've read that you must provide the property names but am unsure

    If VB6, ensure you do not have any control names, function/sub names or form names that use the name Password or UserName.
    It's VB5 But still, it's not the problem with same names and .Text really does't work..

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Arguement Not Optional?

    I think you may have a naming issue or indexing issue as I mentioned. If you dont' find an answer, you may want to zip up your form or project so we can take a look.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: Arguement Not Optional?

    If its not the MsgBox than it is this, but you should change the messagebox call like i mentioned
    Code:
    If Username = txtUsername.Text And Password = txtPassword.Text Then
    No, that wont do!

  8. #8
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: Arguement Not Optional?

    Btw, your code works for me, im using VB6
    No, that wont do!

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: Arguement Not Optional?

    Think this zip has everything needed..
    Attached Files Attached Files

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Arguement Not Optional?

    txtUserName and txtPassword are indexed. Their Index property is not blank, it has a number there. So, you must include the index with the control name, i.e.,
    txtUserName(0).Text and txtPassword(1).Text.

    Optionally, change the Index properties, from the property sheet, for those textboxes to be blank.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: Arguement Not Optional?

    Quote Originally Posted by LaVolpe View Post
    txtUserName and txtPassword are indexed. Their Index property is not blank, it has a number there. So, you must include the index with the control name, i.e.,
    txtUserName(0).Text and txtPassword(1).Text.

    Optionally, change the Index properties, from the property sheet, for those textboxes to be blank.
    Awesome, it's stopped the error.. Just wont do anything when i click the button now?

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: Arguement Not Optional?

    No worries, ignore that last post.. Was just naming problems that i was messing with..

    Thanks Guys, Big Help

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Arguement Not Optional?

    You need to help us understand better? What exactly do you mean, "won't do anything". The button will either show a message box or display your frmLoginSuccess form, if it exists.

    You didn't rename your command button did you? It is still named cmdLogin?

    Edited: Cool, you figured it out. Please mark this post as resolved if it is resolved now.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: Arguement Not Optional?

    Quote Originally Posted by PGTibs View Post
    No worries, ignore that last post.. Was just naming problems that i was messing with..

    Thanks Guys, Big Help

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