3 Replies - 890 Views - Last Post: 17 February 2013 - 10:32 AM Rate Topic: -----

#1 zaneg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-February 13

password and username array problem

Posted 16 February 2013 - 09:27 PM

i know it says you wont do my homework but i am having alot of problems with my username and passwords array
 Dim count = 0
        Dim username() As String = {"user", "userr", "userrr"}
        Dim password() As String = {"pass", "pass", "pass"}
        Dim pass, user As String

        user = username(0)
        pass = password(0)

        If txtuser.Text = username(count) And txtpass.Text = password(count) Then
            play.Show()

        Else
            count = count + 1

            If count = 2 Then
                MsgBox("incorrect")
                Me.Close()
            End If
        End If


what i am attempting to do is make sure that the corresponding username and password is correct and if any1 would like to give me a way to detect how many usernames i have in the array so i can tell it when to stop looking this would help me so much for my major work thanks

Is This A Good Question/Topic? 0
  • +

Replies To: password and username array problem

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9387
  • View blog
  • Posts: 35,242
  • Joined: 12-June 08

Re: password and username array problem

Posted 16 February 2013 - 09:55 PM

It's an array... so use a for loop to go through each name, see if it matches the password, KEEP TRACK OF THE INDEX YOU ARE ON, and if it is found check to see if that corresponding index in the password array matches.
Was This Post Helpful? 0
  • +
  • -

#3 IronRazer  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 328
  • View blog
  • Posts: 994
  • Joined: 01-February 13

Re: password and username array problem

Posted 17 February 2013 - 07:59 AM

View Postzaneg, on 16 February 2013 - 11:27 PM, said:

what i am attempting to do is make sure that the corresponding username and password is correct and if any1 would like to give me a way to detect how many usernames i have in the array so i can tell it when to stop looking this would help me so much for my major work thanks


To check how many names are in (username) you can use (username.length). For example username.length would equal 3 in your array. However arrays are zero indexed meaning the 1st name would be stored in username(0), 2nd name in username(1), and so on. This is an example of how you could do it. You may want to do it a different way but, this will give you an idea of how you could check them and see a way you can get the count of names in your array.

Public Class Form1
    Dim username() As String = {"user", "userr", "userrr"}
    Dim password() As String = {"pass", "pass", "pass"}

    Private Sub Button_Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Login.Click
        Dim matched As Boolean = False

        For count = 0 To username.Length - 1 'username.length counts the number of strings in username
            If txtuser.Text = username(count) And txtpass.Text = password(count) Then
                matched = True
                Exit For 'The name & password match so no need to check the rest.
            End If
        Next

        If matched = True Then
            MessageBox.Show("Show Play Form")
            'play.Show()
        Else
            MessageBox.Show("incorrect")
            Me.Close()
        End If

    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9387
  • View blog
  • Posts: 35,242
  • Joined: 12-June 08

Re: password and username array problem

Posted 17 February 2013 - 10:32 AM

Well let's not just give out code for homework assignments, mkay?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1