reading data from txt file
-
Hi! Looks I have a very simple problem, buts its killing me. I want to read data from a text file and put it to a unique variable. For example: data in Text file looks like 10 20 50 60 20 40 60 20 80 90 I want to read so that say a=10, b=20, c=50, d=60, e=20, f=40 and so forth. usually in fortran etc. it used to be simple: read a,b,c,d,e,f.... How should it work in vb.net Thanks. Amanjot
-
Hi! Looks I have a very simple problem, buts its killing me. I want to read data from a text file and put it to a unique variable. For example: data in Text file looks like 10 20 50 60 20 40 60 20 80 90 I want to read so that say a=10, b=20, c=50, d=60, e=20, f=40 and so forth. usually in fortran etc. it used to be simple: read a,b,c,d,e,f.... How should it work in vb.net Thanks. Amanjot
Do you know how many inputs you are going to have in the file. If you don't it will be a little difficult. This sounds like a perfect time to use a Vector to me. Brian Van Beek My Blog is Awesome, ok maybe not, but is still fun!!
-
Hi! Looks I have a very simple problem, buts its killing me. I want to read data from a text file and put it to a unique variable. For example: data in Text file looks like 10 20 50 60 20 40 60 20 80 90 I want to read so that say a=10, b=20, c=50, d=60, e=20, f=40 and so forth. usually in fortran etc. it used to be simple: read a,b,c,d,e,f.... How should it work in vb.net Thanks. Amanjot
Hi Amanjot; Here is one way to do it. ' Array to hold each number in the file Dim intArray(0) As Integer ' Line of numers read from file Dim inputText As String ' String to hold each value from input line Dim splitText(20) As String ' Index into integer array Dim index As Integer = 0 ' Size of integer array holding values Dim arraySize As Integer = -1 Dim reader As StreamReader = New StreamReader("c:\temp\integerfile.txt") Do ' Read a line of text from file inputText = reader.ReadLine ' Parse the line of integers splitText = inputText.Split(" ") ' Calculate the size need for new values arraySize += splitText.Length ' Resize the array to hold new values ReDim Preserve intArray(arraySize) ' Put each value into a unique variable For Each numberString As String In splitText intArray(index) = CInt(numberString) index += 1 Next ' ChecK to see if there are any more input Loop Until reader.Peek = -1 .... reader.Close() I hope that this was of some help -Fernando :)
-
Do you know how many inputs you are going to have in the file. If you don't it will be a little difficult. This sounds like a perfect time to use a Vector to me. Brian Van Beek My Blog is Awesome, ok maybe not, but is still fun!!