0
Dim lines As String() = IO.File.ReadAllLines(FILE_NAME)

If System.IO.File.Exists(FILE_NAME) = True Then

    For i = 0 To lines.Count - 1

        Dim userkey As String = System.IO.File.ReadAllLines(FILE_NAME)(i)

        If key.Text.Contains(userkey) Then
            'shows many msgs at  once i want to show only one msg
            MsgBox("Thanks for registering ")
        Else

        End If

        If Not key.Text.Contains(userkey) Then
            MsgBox("Code error ")
        End If

    Next

End If

Edited by Reverend Jim: Fixed code formatting

2
Contributors
1
Reply
18
Views
2 Years
Discussion Span
Last Post by Reverend Jim
0

The first problem is that you are reading the entire file on every iteration of the loop. Read the entire file once before the loop, then iterate over the lines. Or you could read the file once and use a For Each as in

Dim found As Boolean = False

For Each userkey As String in System.IO.File.ReadAllLines(FILE_NAME)
    If key.Text.Contains(userkey) Then
        found = True
        Exit For
    End If
Next

If found Then
    MsgBox("Thanks for registering ")
Else
    MsgBox("Code error ")
End If

However, I think you should be using

If key.Text = userkey Then

instead so that you don't get a false match when key.Text = "sernam" and userkey = "username".

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.