PDA

View Full Version : File input


daveyisu
03-25-04, 03:28 PM
Being used to VB6, the file input of VB.NET has got me very confused.

I have a file that is similar in form to this:

0.00 0.00 1.0564
1.00 0.00 0.023
0.00 1.00 0.0341
1.00 1.00 0.13453
0.00 2.00 1.236
1.00 2.00 0.0578

I need to input each of those numbers into a separate variable, all dimensioned as singles, ie.

Row = 0.00
Col = 0.00
Height = 1.0564

for the first line of data. In VB6 I could simply use the line

Input#1, row, col, height

but I have no idea how to do this in VB.NET.

I have read about the streamreader etc, but the best I've been able to come up with is a string that has all 3 values in it. I can't even read the file by byte size, because it can change.

Any help would be greatly appreciate.

Thanks

David

Shane
03-25-04, 05:08 PM
Being used to VB6, the file input of VB.NET has got me very confused.

I have a file that is similar in form to this:

0.00 0.00 1.0564
1.00 0.00 0.023
0.00 1.00 0.0341
1.00 1.00 0.13453
0.00 2.00 1.236
1.00 2.00 0.0578

I need to input each of those numbers into a separate variable, all dimensioned as singles, ie.

Row = 0.00
Col = 0.00
Height = 1.0564

for the first line of data. In VB6 I could simply use the line

Input#1, row, col, height

but I have no idea how to do this in VB.NET.

I have read about the streamreader etc, but the best I've been able to come up with is a string that has all 3 values in it. I can't even read the file by byte size, because it can change.

Any help would be greatly appreciate.

Thanks

David
Dim sr As StreamReader = New StreamReader("c:\TestFile.txt")

Dim line As String

Dim Row As Single

Dim Column As Single

Dim Height As Single

Dim line_array As String()



Do

line = sr.ReadLine()

If Not line IsNothing Then

line_array = line.Split(" ")

Row = Convert.ToSingle(line_array(0))

Column = Convert.ToSingle(line_array(1))

Height = Convert.ToSingle(line_array(2))

MessageBox.Show("Row is " & Row.ToString() & vbNewLine & "Column is " & Column.ToString() & vbNewLine & "Height is " & Height.ToString())

EndIf

Loop Until line Is Nothing