Results 1 to 6 of 6

Thread: reading from a text file

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    toronto
    Posts
    12

    reading from a text file

    can anyone check and see what wrong with this code. i'm trying to read from a usernames and passwords from that file which i have coded in a text file.

    Dim mAttempts As Integer
    Dim Uname, pass As String
    Dim sr As IO.StreamReader = IO.File.OpenText("user.txt")
    Do While (sr.Peek <> -1)
    Uname = sr.ReadLine
    pass = sr.ReadLine

    If txtUsername.Text = "" Then
    MsgBox("User Name cannot be blank", MsgBoxStyle.Information)
    Exit Sub
    End If
    If TxtPassword.Text = "" Then
    MsgBox("Password cannot be blank", MsgBoxStyle.Information)
    Exit Sub
    End If

    mAttempts = mAttempts + 1
    If Uname <> txtUsername.Text Or pass = TxtPassword.Text Then
    MsgBox("Please verify User Name and Password", MsgBoxStyle.Information)
    ElseIf Uname = txtUsername.Text And pass = TxtPassword.Text Then
    MsgBox("Logged in", MsgBoxStyle.Information)
    If mAttempts = 3 Then
    MsgBox("You had just 3 chances to verify")
    End
    End If
    End If
    Loop
    sr.Close()
    Exit Sub

  2. #2
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724

    Re: reading from a text file

    Originally posted by freddie_26
    can anyone check and see what wrong with this code. i'm trying to read from a usernames and passwords from that file which i have coded in a text file.

    Dim mAttempts As Integer
    Dim Uname, pass As String
    Dim sr As IO.StreamReader = IO.File.OpenText("user.txt")
    Do While (sr.Peek <> -1)
    Uname = sr.ReadLine
    pass = sr.ReadLine

    If txtUsername.Text = "" Then
    MsgBox("User Name cannot be blank", MsgBoxStyle.Information)
    Exit Sub
    End If
    If TxtPassword.Text = "" Then
    MsgBox("Password cannot be blank", MsgBoxStyle.Information)
    Exit Sub
    End If

    mAttempts = mAttempts + 1
    If Uname <> txtUsername.Text Or pass = TxtPassword.Text Then
    MsgBox("Please verify User Name and Password", MsgBoxStyle.Information)
    ElseIf Uname = txtUsername.Text And pass = TxtPassword.Text Then
    MsgBox("Logged in", MsgBoxStyle.Information)
    If mAttempts = 3 Then
    MsgBox("You had just 3 chances to verify")
    End
    End If
    End If
    Loop
    sr.Close()
    Exit Sub

    what is the problem u get any error.. be specify to get help faster...

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    toronto
    Posts
    12
    the code is being run but when i enter the username and password and error is generated and a grenn line appear over the

    dim sr as io.streamreader =

  4. #4
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724
    currently i am away from my desk... so cannot test it... what is the message u get try using try ....catch...end try and see what is the error message u get

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    I do not have .Net on this machine, but I think it should be:

    VB Code:
    1. Dim sr As IO.StreamReader = New IO.File.OpenText("user.txt")

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Make sure you are referring to the right path .

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