i have a text file with the following data:
Calculated Concentrations
30.55 73.48 298.25 27.39 40.98 11.21 99.22 33.46 73.99 12.18 30.7
50 28.4 34.33 29.55 70.48 43.09 28.54 50.78 9.68 62.03 63.18 28.4
100 23.83 68.65 10.93 ?????? 31.42 8.16 24.97 8.3 114.97 34.92 15.53
200 32.15 29.98 23.69 ?????? 23.41 33.6 92.03 32.73 13.58 58.44 94.61
400 159.98 18.05 50.94 37.12 15.25 46.75 315.22 69.98 13.58 ?????? 58.77
208.82 11.07 38.15 86.31 35.5 41.88 28.25 5.39 40.83 29.98 54.42 69.48
36.09 13.16 23.26 19.31 147.56 31.86 6.77 19.45 33.6 32.87 205.47 134.21
?????? 17.35 9.96 58.61 13.44 23.97 22.13 145.17 29.55 26.54 37.12 198.33
and i would like to load this data into an array.
- how do i enable the user to open a file of his choosing in vb.net?
- how do i read these values into an array in vb.net?
i would like to clarify that what person-b has suggested works very very well. specifically the fields = calculationText.split(” “) was exactly what i needed; however, my next issue is the following. the data above is actually in this format:
where the i need the first value to be 0, then 50, then 100 etc. and i need it to read columns from left to right. the problem is that the values are not reading into the array in this manner. the values are actually reading like this: 6.65, 84.22, ????, 35.15. please help!
To read a file into a
Stringvariable, in VB.NET, you can use theSystem.IO.File.ReadAllText()function. An example is:Where
"calculations.txt"is the file name.To your next point – to allow the user to load a file of their choosing, you can use the
OpenFileDialogtype. An example:Combining this, we get:
Now, we need to process the input. First, we need to make a list of decimal numbers. Next, we put everything in the file that is a number in the list:
This won’t include
Calculated Concentrationsor?????in the list. For usable code, just combine the second and last code samples.EDIT: In response to the comment below.
With
Listobjects, you can index them like this:You do not need to use the
Itemproperty. Also, when showing it in a message box, you need to turn it into aStringtype first, like this: