G
Guest
I have this text file below saved in my c: directory
FeedA:100:200:400:233:564:10:237200:400:233
FeedB:267:126:548:128:675:16:293:567:89
FeedC:162:654:876:918:727:81:891:75:554
FeedD:576:713:373:187:931:38:918:87:98
FeedE:102:650:896:908:729:813:791:55:87
FeedF:56:313:673:467:731:382:718:43:76
FeedG:12:54:889:978:726:834:892:32:432
FeedH:57:813:333:189:971:34:914:432:87
I am trying to read all of this data into an array, each colon represents a
different element, but i am having problems.
I am doing this using the vb.net smart device application. I am prepared to
store my text file differently if this helps,(should there be a ':' after
each 'element'?) but i will need to perform calculations on elements within
the array when it is all read in.
This is the code i have currently, it builds successfully and deploys
successfully to the emulator, but then just as form1 should appear it
displays an error.
My code:
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Windows Form Designer generated code
Dim sr1 As StreamReader = File.OpenText("C:\feed.text")
Dim arrInfoTemp(9) As String
Dim arr1() As string 'i originally had this line as Dim arr1 as Array,
'but was told to change it to the above
Dim sStr1 As String
Dim iCount As Integer
Dim arrInfoCount As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
arrInfoCount = -10
Do Until sr1.Peek = -1
arrInfoCount += 10
sStr1 = sr1.ReadLine
arr1 = Split(sStr1, ":")
ReDim Preserve arrInfoTemp(arrInfoCount + 10)
For iCount = 0 To 9
arrInfoTemp(arrInfoCount + iCount) = arr1(iCount)
Next
ReDim Preserve arrInfoTemp(arrInfoCount + 9)
Loop
sr1.Close()
arrInfoCount = arrInfoTemp.GetUpperBound(0)
Dim arrInfo((arrInfoCount + 1) / 10 - 1, 10) As String
For iCount = 0 To (arrInfoCount + 1) / 10 - 1
For arrInfoCount = 0 To 9
arrInfo(iCount, arrInfoCount) = arrInfoTemp(iCount * 10 + arrInfoCount)
Next
Next
End Sub
End Class
FeedA:100:200:400:233:564:10:237200:400:233
FeedB:267:126:548:128:675:16:293:567:89
FeedC:162:654:876:918:727:81:891:75:554
FeedD:576:713:373:187:931:38:918:87:98
FeedE:102:650:896:908:729:813:791:55:87
FeedF:56:313:673:467:731:382:718:43:76
FeedG:12:54:889:978:726:834:892:32:432
FeedH:57:813:333:189:971:34:914:432:87
I am trying to read all of this data into an array, each colon represents a
different element, but i am having problems.
I am doing this using the vb.net smart device application. I am prepared to
store my text file differently if this helps,(should there be a ':' after
each 'element'?) but i will need to perform calculations on elements within
the array when it is all read in.
This is the code i have currently, it builds successfully and deploys
successfully to the emulator, but then just as form1 should appear it
displays an error.
My code:
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Windows Form Designer generated code
Dim sr1 As StreamReader = File.OpenText("C:\feed.text")
Dim arrInfoTemp(9) As String
Dim arr1() As string 'i originally had this line as Dim arr1 as Array,
'but was told to change it to the above
Dim sStr1 As String
Dim iCount As Integer
Dim arrInfoCount As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
arrInfoCount = -10
Do Until sr1.Peek = -1
arrInfoCount += 10
sStr1 = sr1.ReadLine
arr1 = Split(sStr1, ":")
ReDim Preserve arrInfoTemp(arrInfoCount + 10)
For iCount = 0 To 9
arrInfoTemp(arrInfoCount + iCount) = arr1(iCount)
Next
ReDim Preserve arrInfoTemp(arrInfoCount + 9)
Loop
sr1.Close()
arrInfoCount = arrInfoTemp.GetUpperBound(0)
Dim arrInfo((arrInfoCount + 1) / 10 - 1, 10) As String
For iCount = 0 To (arrInfoCount + 1) / 10 - 1
For arrInfoCount = 0 To 9
arrInfo(iCount, arrInfoCount) = arrInfoTemp(iCount * 10 + arrInfoCount)
Next
Next
End Sub
End Class