Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27072

[RESOLVED] Message box not functioning how i want

$
0
0
Hi, I am in an introduction to Visual basic course and am trying to write a program similar to an ATM machine. I have a text file with some fake user bank accounts. I am trying to make a little text box on the top of the program where you enter in an 8 digit user ID and if it matches one of the ID's in the text file it will pop up a message box saying "hello" and if it does not match I want a message box saying "Please Enter a Valid ID". For some reason if I enter in a correct ID the error box pops up once (I close it) then the welcome box pops up and then after I close that the error box keeps popping up endlessly.

Here is a picture of how the code looks

Here is the brief code i have on the part (i am a super beginner so it might be really bad)

Code:

Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        Dim inputid As String
        inputid = txtID.Text
        Dim name As String
        Dim k As Integer

        For k = 0 To account.Length - 1
            If inputid = account(k).id Then
                name = account(k).name
                MessageBox.Show("Hello, " & name)
               
            Else
                MessageBox.Show("Please Enter a Valid ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If
        Next


    End Sub






In case you Need it here is the part of the code where I read in the information from the text file (this is how our teacher taught us to do it)
Code:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim infilestr As IO.StreamReader
        Dim i As Integer
        Dim line As String

        infilestr = IO.File.OpenText("accountinfo.txt")

        Do While Not infilestr.EndOfStream
            i = i + 1
            ReDim Preserve account(i)
            line = infilestr.ReadLine
            account(i).name = line.Split(",")(0)
            account(i).id = line.Split(",")(1)
            account(i).checkingBal = line.Split(",")(2)
            account(i).savingsBal = line.Split(",")(3)
        Loop

        infilestr.Close()
    End Sub

Attached Images
 

Viewing all articles
Browse latest Browse all 27072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>