Visual Basic - Read Last Line of .txt then Split Problems!

vanquished

Limp Gawd
Joined
Oct 29, 2002
Messages
359
Hiya,

Please forgive me if I'm making a fool of myself, I've never really touched VB before until now!

I'm making a program which will display a wind turbine's power output. I'm taking that data from a control box's log file which is, i think a Tab delimited text file. The output of the log is like this:

4.50 WSW 0.27 6.3 WSW

what i've got so far looks like this:

Dim sr As StreamReader = IO.File.OpenText("C:\Users\xxxx\Documents\New Energy Files\weather.txt")
Dim strTemp As String
Dim array(10) As String

Do While sr.Peek <> -1
strTemp = sr.ReadLine
Loop

MsgBox(strTemp(1))
End Sub

What I want the message box to display is 'WSW' but at the moment it displays '.' I have tried to use the split function but it doesn't seem to have any effect! no matter what I put, it seems that 'strTemp' has already been split into single characters. While this does function, 4.5 can sometime become 11.5 and so using the position of the character in the array will not always work.

How can I split strTemp into more than just 1 character?

Please help!
 
you need to assign the split function to an array:

Dim logOutput As String() = Split(strTemp, " ")

then access the elements you want:

MsgBox(logOutput(0) & " " & logOutput(1))

which will pop up "4.50 WSW" using your sample data.
 
no matter what I put, it seems that 'strTemp' has already been split into single characters

It shouldnt do, heres a piece of code from one of my older projects which looks exactly like the sort of thing your on about. The message box prompt is always the last line of the text file.

Is it possible that the output files are not 100% text and have some linefeeds in? Try opening it in wordpad and see (notepad doesnt show unix style linefeeds)

A grab of the code i used

Dim strTemp
Dim r As StreamReader
Dim rFile As System.IO.File
r = rFile.OpenText("c:\videobitrate.txt")
While r.Peek <> -1
strTemp = r.ReadLine
End While
r.Close()
Msgbox(strTemp)
 
Back
Top