I am trying to import data from a text file into an array using VB.Net 2005. What I want to do is parse the data in VB.Net and then export the data back to a text file. The problem I am having is I am not quite sure how to get each line of data brought in a a separate array element. From doing searches I have seen refernces to vbctrlf but haven't been able to find out how to apply it in my case.
My code so far is as follows:
' Project name: Summarize Multiple Transaction Exports by Client Number Project
' Project purpose: The project imports transactions and summarizes all data by the Client Number,
'
'
' Created/revised: Me on December 17, 2008
Option Explicit On
Option Strict On
Public Class MainForm
Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' load from the text file the product item numbers nad prices
' declare the variables used
Dim inputfile As String = "Exports.txt"
Dim filecontents As String
Dim lineindex As Integer
' check to make sure the file exists, and if yes then
' get the contents of the file. If not, display message.
If My.Computer.FileSystem.FileExists(inputfile) Then
filecontents = My.Computer.FileSystem.ReadAllText(inputfile)
Else
MessageBox.Show("File does not exist", "Exports.txt", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
'find first newline in string
lineindex = filecontents.IndexOf(ControlChars.NewLine)
' dimension array to store each line in the Exports.txt file
Dim transaction(lineindex) As String
Dim counter As Integer = 0
' run through data to store each transaction in the transaction array
' Do Until lineindex - counter <= 0
' transaction(counter)=
'
' Loop
End sub
End Class
Can anyone point me in the right direction for bring each line of the text file into an array element?
so for exaple, if my test file contains:
546.34 (tab delimiter) 123456
745.35 (tab delimiter) 567890
123.45 (tab delimiter) 987654
I would want the array to have:
transaction(0)=546.34 (tab delimiter) 123456
transaction(1)=745.35 (tab delimiter) 567890
transaction(2)=123.45 (tab delimiter) 987654
After I get everything into the array, I'll parse the data with string manipulation....which I think I can do....and then I'll export the data back to a text file.....which also, I think I can do.
Thanks in advance for any assistance!

New Topic/Question
Reply




MultiQuote



|