Hello,
I seem to be having a problem with a dynamic variable array.
I am trying to read usernames and their corresponding passwords from a text file, but the array only loads the first pair. The highest subscript I reach (after doing tests), is 0.
This is the code I used for the whole Login form:
Please help me. Thanks.Code:Dim username(), password() As String Public LoginSucceeded As Boolean Dim i Dim LoggedUser As String Private Sub cmdCancel_Click() LoginSucceeded = False End End Sub Private Sub cmdOK_Click() i = 0 For i = LBound(username) To UBound(username) If txtUserName = username(i) And txtPassword = password(i) Then LoggedUser = username(i) MsgBox "You have successfuly logged in!" frmChat.Show Me.Hide GoTo theline Else MsgBox "Invalid username and/or password!" End End If Next theline: End Sub Private Sub Form_Load() i = 0 ReDim username(i) ReDim password(i) Open "D:\VB Stuff\Users.txt" For Input As #2 Do While Not EOF(2) ReDim Preserve username(i) ReDim Preserve password(i) Input #2, username(i), password(i) i = i + 1 Loop Close #2 End Sub




Reply With Quote