By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,644 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,644 IT Pros & Developers. It's quick & easy.

Do while loop

P: 7
I have a do while loop thats reading from a file. I have two forms in my program and the file is reading four lines the acct number, which is entered in the prior form as a login. The lines in the file each have a different account number above them. I want to read only the files below the certain account number.

file setup(lines in the txt file)
987654
D
60
11/22/2007
987654
D
60
11/23/2007
987654
D
45
11/24/2007
987654
W
79
11/26/2007

etc...

I am reading the file to get a sum for that account number the D's are deposits and W's are withdrawals.
Expand|Select|Wrap|Line Numbers
  1.  Dim sr As IO.StreamReader
  2.     Dim Acctname, Acctaddress, Acctnumber, sum As String
  3.  
  4.  
  5.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Me.Text = "RBD Bank"
  7.         OpenFile()
  8.         Do While (Acctnumber <> frmLogin.txtaccount.Text) And (sr.Peek <> -1)
  9.             Acctnumber = sr.ReadLine
  10.             Acctname = sr.ReadLine
  11.             Acctaddress = sr.ReadLine
  12.         Loop
  13.  
  14.         Dim fmtstr As String = "{0,-20}"
  15.         lstaddress.Text = lstaddress.Items.Add(String.Format(fmtstr, Acctnumber))
  16.         lstaddress.Text = lstaddress.Items.Add(String.Format(fmtstr, Acctname))
  17.         lstaddress.Text = lstaddress.Items.Add(String.Format(fmtstr, Acctaddress))
  18.         lstaddress.Show()
  19.         CloseFile()
  20.     End Sub
  21.  
  22.     Sub OpenFile() 'Opens the File, make sure it is in the Bin folder
  23.         sr = IO.File.OpenText("accounts.txt")
  24.     End Sub
  25.     Sub OpenFile2() 'Opens the File, make sure it is in the Bin folder
  26.         sr = IO.File.OpenText("transactions.txt")
  27.     End Sub
  28.     Sub CloseFile() 'Closes the file
  29.         sr.Close()
  30.     End Sub
  31.  
  32.  
  33.  
  34.     Private Sub btnAcctBalance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAcctBalance.Click
  35.         Dim Transtype, amount, transdate, acctnum As String
  36.         OpenFile2()
  37.         Do Until acctnum <> Acctnumber    'I think the problem is right here but dunno how to tell it to read only the account number I entered
  38.             acctnum = sr.ReadLine()
  39.             Transtype = sr.ReadLine()
  40.             amount = sr.ReadLine()
  41.             transdate = sr.ReadLine()
  42.             If Transtype = "W" Then
  43.                 sum -= CDbl(amount)
  44.             ElseIf Transtype = "D" Then
  45.                 sum += CDbl(amount)
  46.             End If
  47.         Loop
  48.         CloseFile()
  49.         MsgBox(sum, MsgBoxStyle.Information, "Current Account Balance")
  50.     End Sub
  51.  
  52.     Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
  53.         Me.Close()
  54.         frmLogin.Close()
  55.     End Sub
  56. End Class
  57.  
I think i am needing something different in line 37
Dec 1 '07 #1
Share this Question
Share on Google+
1 Reply


P: 7
I figured it out, needed a nested if statement to verify the correct account number.
Dec 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.