Announcement

Collapse
No announcement yet.

VB 2005 help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB 2005 help

    I need help with my VB prog, so basically its a Login App that has a textbox for Username and password, with the labels and w/e. So i already have everything prepared for actual third party input, i have the text in username(username.text) < 5 characters to display too short. I have a bunch of those kinds of things, now i created an Array called MyUserNameArray. I want the application to verify that the username.text is a value within the UserNameArray. And I also have an array for passwords, with Password.Text and w/e.

    So it basically looks like this (i know its probably way wrong, try to understand what im doing):

    If (Username.Text.Length < 5) Then MessageBox.Show("Username is too short, please try again")
    Dim MyUserNameArray() As String
    MyUsernameArray = MyUserNameArray("Billy123, winter4, autumn69, spring9669")
    //i have no freekin clue what im doing int he above
    If Username.Text.Contains(MyUserNameArray()) Then MessageBox.Show("Excellent, Your login was sucessful") Else MessageBox.Show("Your Username is Invalid")

    I also tried chaning the 4th line to: If Username.Text(MyUserNameArray)

    helppp
    4:BigKing> xD
    4:Best> i'm leaving chat
    4:BigKing> what did i do???
    4:Best> told you repeatedly you cannot use that emoji anymore
    4:BigKing> ???? why though
    4:Best> you're 6'4 and black...you can't use emojis like that
    4:BigKing> xD

  • #2
    Is that all the code you've written? If not then please post everything, I really want to see more of your coding.
    Da1andonly> man this youghurt only made me angry

    5:ph> n0ah will dangle from a helicopter ladder and just reduce the landscape to ashes by sweeping his beard across it

    Comment


    • #3
      You need to access a single element within the array, loop through it and compare it to the textBox value. Most Array datatypes are zero based also.

      Comment


      • #4
        But it isn't an array, it's just a string called something that had the word Array in it!
        Da1andonly> man this youghurt only made me angry

        5:ph> n0ah will dangle from a helicopter ladder and just reduce the landscape to ashes by sweeping his beard across it

        Comment


        • #5
          Originally posted by paradise! View Post
          Dim MyUserNameArray() As String
          MyUsernameArray = MyUserNameArray("Billy123, winter4, autumn69, spring9669")
          I am not a VBer, so I don't know the syntax really, but I think it should be more like:

          //declare a variable
          Dim MyUsernameArray

          //asigning an array -filled with Strings- to the variable
          MyUsernameArray = Array("Billy123","winter4","autumn69","spring9669" )
          You ate some priest porridge

          Comment


          • #6
            You might be able to get away with
            Dim MyUsernameArray("Billy123","winter4","autumn69","s pring9669") As String

            I haven't used VB in a long time, but I assume you recall values as an index of the array.

            So would MyUsernameArray(1) return Billy123? (Assuming 1 base index, winter4 if it's 0 base)

            If so, I guess you need to set up a for loop from 1 to 5 (or 0 to 4)

            EDIT:
            The above bit has been superseded by my next post, but the bit below still is needed:

            In pseudocode

            Code:
            j = 0
            for i = 1 to 5                                            //This for loop checks the input 
                If Username.Text == MyUsernameArray(i)  //value vs each password in
                    j = 1                                               //the array, setting j = 1
                End                                                     // if it matches any.
            End
            
            If j = 1                                                    //This if statement checks
                print("Login Successful!")                        //if j = 1, and if it is
            Else                                                        //then it will let you log in
                print("I am sorry, your username is not recognised")
            End
            I don't know enough about VB syntax to be able to translate the for loop or if statement into Visual Basic for you, but hell, this is your work not mine anyway.
            Last edited by Ewan; 06-23-2008, 11:26 AM.
            USS Banana after years of superior jav play has amassed 17999 kills, he is 1 kill away from 18k, Type ?go Javs FOR A GAME OF HUNT (no scorereset) -Kim
            ---A few minutes later---
            9:cool koen> you scorereseted
            9:Kim> UM
            9:Kim> i didn't
            9:cool koen> hahahahahahaha
            9:ph <ZH>> LOOOOL
            9:Stargazer <ER>> WHO FUCKING SCORERESET
            9:pascone> lol?

            Comment


            • #7
              Ok I've had a look, I am pretty sure you have to do the array like this:

              Dim MyUsernameArray(1 to 5) As String

              MyUsernameArray(1) = "Billy123"
              MyUsernameArray(2) = "winter4"

              etc
              etc

              The thing I put in pseudocode in my last post still applies.
              USS Banana after years of superior jav play has amassed 17999 kills, he is 1 kill away from 18k, Type ?go Javs FOR A GAME OF HUNT (no scorereset) -Kim
              ---A few minutes later---
              9:cool koen> you scorereseted
              9:Kim> UM
              9:Kim> i didn't
              9:cool koen> hahahahahahaha
              9:ph <ZH>> LOOOOL
              9:Stargazer <ER>> WHO FUCKING SCORERESET
              9:pascone> lol?

              Comment


              • #8
                Originally posted by Ewan View Post
                Ok I've had a look, I am pretty sure you have to do the array like this:

                Dim MyUsernameArray(1 to 5) As String

                MyUsernameArray(1) = "Billy123"
                MyUsernameArray(2) = "winter4"

                etc
                etc

                The thing I put in pseudocode in my last post still applies.
                nononono, i know there is an easier way than this, there has to be. There is a function that checks if the input was a value within the array(which i defined as string), so why do i need to make it numbers? Idk ive seen it in java.
                4:BigKing> xD
                4:Best> i'm leaving chat
                4:BigKing> what did i do???
                4:Best> told you repeatedly you cannot use that emoji anymore
                4:BigKing> ???? why though
                4:Best> you're 6'4 and black...you can't use emojis like that
                4:BigKing> xD

                Comment


                • #9
                  Originally posted by Zerzera View Post
                  I am not a VBer, so I don't know the syntax really, but I think it should be more like:

                  //declare a variable
                  Dim MyUsernameArray

                  //asigning an array -filled with Strings- to the variable
                  MyUsernameArray = Array("Billy123","winter4","autumn69","spring9669" )
                  You have to assign a data type (i think) when you declare, i put mine Dim MyUsernameArray As String, i mean you have to say the array is text dontcha? But then again it really shouldnt matter what data type it is, as long as it is an array it can be numbers or text or both, look now im ranting.

                  Originally posted by Kolar View Post
                  You need to access a single element within the array, loop through it and compare it to the textBox value. Most Array datatypes are zero based also.
                  Nice and vague Kolar.... Thats what im trying to do..
                  4:BigKing> xD
                  4:Best> i'm leaving chat
                  4:BigKing> what did i do???
                  4:Best> told you repeatedly you cannot use that emoji anymore
                  4:BigKing> ???? why though
                  4:Best> you're 6'4 and black...you can't use emojis like that
                  4:BigKing> xD

                  Comment


                  • #10
                    Code

                    Code:
                    Dim LoginIndex = Array.IndexOf(MyUsernameArray, Username.Text)
                    
                    if WordIndex < 0 then
                      MessageBox.Show("Bad username")
                    else
                       if Password.Text = MyUsernameArray(WordIndex) then
                         MessageBox.Show("Correct username and password")
                       else
                         MessageBox.Show("Correct username but bad password")

                    Comment


                    • #11
                      Originally posted by Nockm View Post
                      Code

                      Code:
                      Dim LoginIndex = Array.IndexOf(MyUsernameArray, Username.Text)
                      
                      if WordIndex < 0 then
                        MessageBox.Show("Bad username")
                      else
                         if Password.Text = MyUsernameArray(WordIndex) then
                           MessageBox.Show("Correct username and password")
                         else
                           MessageBox.Show("Correct username but bad password")
                      Can you explain the args of IndexOf..I understand getting the index of usernameArray but not username.text
                      4:BigKing> xD
                      4:Best> i'm leaving chat
                      4:BigKing> what did i do???
                      4:Best> told you repeatedly you cannot use that emoji anymore
                      4:BigKing> ???? why though
                      4:Best> you're 6'4 and black...you can't use emojis like that
                      4:BigKing> xD

                      Comment


                      • #12
                        Originally posted by paradise! View Post
                        nononono, i know there is an easier way than this, there has to be. There is a function that checks if the input was a value within the array(which i defined as string), so why do i need to make it numbers? Idk ive seen it in java.
                        This is setting up the array, not finding the values within.

                        What you have done, is set an array with 1 long string "Billy123, winter4, autumn69, spring9669"

                        The way I said there, sets up an array with 5 values, 1 for each of the logins.

                        The For loop then takes the input, and checks it against each of these logins in turn.
                        USS Banana after years of superior jav play has amassed 17999 kills, he is 1 kill away from 18k, Type ?go Javs FOR A GAME OF HUNT (no scorereset) -Kim
                        ---A few minutes later---
                        9:cool koen> you scorereseted
                        9:Kim> UM
                        9:Kim> i didn't
                        9:cool koen> hahahahahahaha
                        9:ph <ZH>> LOOOOL
                        9:Stargazer <ER>> WHO FUCKING SCORERESET
                        9:pascone> lol?

                        Comment


                        • #13
                          Originally posted by paradise! View Post
                          Can you explain the args of IndexOf..I understand getting the index of usernameArray but not username.text
                          Arg #1 is the array you are searching within.
                          Arg #2 is the element you are looking for.

                          The array you want to search is the list of usernames... and you want to compare it against what the user wrote... i.e. Username.Text.

                          The result is -1 if the element is not found in the array (if the login is not found in the list of usernames). Otherwise it will return the index where it is first found.

                          Comment


                          • #14
                            Originally posted by Nockm View Post
                            Code

                            Code:
                            Dim LoginIndex = Array.IndexOf(MyUsernameArray, Username.Text)
                            
                            if WordIndex < 0 then
                              MessageBox.Show("Bad username")
                            else
                               if Password.Text = MyUsernameArray(WordIndex) then
                                 MessageBox.Show("Correct username and password")
                               else
                                 MessageBox.Show("Correct username but bad password")
                            You compare the password the user has given -using the the nonexisting variable WordIndex- to a value from the username array?
                            You ate some priest porridge

                            Comment


                            • #15
                              Originally posted by Zerzera View Post
                              You compare the password the user has given -using the the nonexisting variable WordIndex- to a value from the username array?
                              Correction inspired by Zerzera (my hero)

                              Code:
                              Dim LoginIndex = Array.IndexOf(MyUsernameArray, Username.Text)
                              
                              if LoginIndex < 0 then
                                MessageBox.Show("Bad username")
                              else
                                 if Password.Text = MyPasswordArray(LoginIndex) then
                                   MessageBox.Show("Correct username and password")
                                 else
                                   MessageBox.Show("Correct username but bad password")
                              Last edited by Nockm; 06-25-2008, 09:53 AM.

                              Comment

                              Working...
                              X