If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Parsing textlines?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-22-04, 15:49
Jane2004 Jane2004 is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
Question Parsing textlines?

Hi!
I'm retrieving data from a text file.
I try to parse my data into 4 fields: Id, Lastname, Firstname & Grade.
I have a Parse-function, but I think, I'm missing something here because, when I run it, it doesn't show me the required data filled into the 4 fields, it shows me only the 4 fields without the data that it should have pulled from the text file.
Can somebody help me out, please?!?!?!

Dim ID As Integer
Dim Lname, Fname As String
Dim Grade As Double
Try
Dim strFileNAme As String = Directory.GetCurrentDirectory & "\Students.txt"
Dim MyStream As New Streamreader(strFileNAme)
Dim strResult, strLine As String
Dim Ctr As Integer = 0

strResult = MyStream.Readline
Do While Not (strResult Is Nothing)
Ctr += 1
MsgBox(strResult & vbCrLf)
strLine = ParseALine(strResult)
strResult = MyStream.Readline

Loop

MyStream.Close()
MsgBox("ID(0)=" & ID & vbCrLf & "Last Name(0)=" & Lname & vbCrLf & "First Name(0)= " & Fname & vbCrLf & "Grade(0)=" & Grade)
Catch exc As Exception
MsgBox("Error" & exc.Message & vbCrLf & "Project will end here")
End
End Try
End Sub

Private Function ParseALine(ByVal Inline As String) As String
Dim strResult, strTokens() As String
Dim ctr As Integer
strResult = ""
strTokens = Inline.Split(",")
For ctr = 0 To strTokens.GetUpperBound(0)
strResult &= strTokens(ctr).Trim & Space(ColumnWidth - strTokens(ctr).Trim.Length)
Next
Return strResult

End Function
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On