Reading and writing to sequential files.

Hi can anyone tell me how to write numbers and text on a single line and then read it. I need to be able to read the numbers as integer.

I'm using the following code to write a number, and then read it, but I would like to write text next to that number and still be able to retrieve only the number to perform calculations.


'Dim Strings
Dim amount As String = txtDeposit.Text
Dim output As String
Dim balance As Integer


Dim WriteToFile As IO.StreamWriter

'Code to open text file and append to it. Then closes File.
WriteToFile = IO.File.AppendText("A:ChequeAccount.txt")
WriteToFile.WriteLine(amount)
WriteToFile.Close()

'Dim reads as IO.StreamReader object and open File for reading.

Dim reads As IO.StreamReader = IO.File.OpenText("A:ChequeAccount.txt")
Dim readData As Integer


'Do Loop Until all the data is read.
'output takes the values read.


Do
readData = CInt(reads.ReadLine)
balance += readData
output &= FormatCurrency(readData) & vbTab & vbTab & " Deposit." & vbTab & vbTab & "newBal " & FormatCurrency(balance) & vbCrLf
Loop Until reads.ReadLine = ""


'Close File and display in txtBox.
reads.Close()
txtDisplay.Text = output

This code works every second click of the button???

Thanks if you can help.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories