Results 1 to 4 of 4

Thread: help

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    13

    Question help

    i have this code in my program

    Dim account As String
    Dim id As String
    Dim password As String
    Dim position As Integer
    accountsfile = New System.IO.StreamReader("accounts.txt")
    account = accountsfile.ReadLine()
    position = InStr(account, " ")
    id = Microsoft.VisualBasic.Left(account, position - 1)
    password = Mid(account, position + 1)
    If mskAccount.ClipText = id And txtPassword.Text = password Then
    grporderform.Visible = True
    Else
    MsgBox("Account or Password is incorrect. Try again.")
    mskAccount.Focus()
    End If

    but it only reads the first line in the txt file.
    i have other ids and passwords in the txt file, so how do i code it so that it will read those ones as well?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This loops in all the lines in the file
    VB Code:
    1. r = New IO.StreamReader("c:\test.txt")
    2.         While (r.Peek() > -1)
    3.             MessageBox.Show(r.ReadLine)
    4.         End While
    5.         r.Close()

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    13
    thanks, i used it..but i have another question...

    While (accountsfile.Peek() > -1)

    account = accountsfile.ReadLine()
    position = InStr(account, " ")
    id = Microsoft.VisualBasic.Left(account, position - 1)
    password = Mid(account, position + 1)
    If mskAccount.ClipText = id And txtPassword.Text = password Then
    grporderform.Visible = True
    Else

    End If
    End While

    after else, i want to put a msgbox that says that the id or password it invalid, but when i do, and execute the program, type any of the ids or passwords that are valid, the msgbox will appear, and after clicking okay a few times, it will eventually stop and continue with the rest of the program. how can i add the msgbox?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I don't really understand this condition but you can always use Exit While or Exit Sub where you want to get out of the loop .

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