I have visual basic 2010 windows application assignment in which I have to populate a one dimensional array from a text file stored in the projects debug folder. The text file is 6 five digit numbers on seperate lines. One number was typed then enter was pressed 6 times. The following is copied and pasted from the text file:
I have to populate a one dimensional array. This is the declaration I am using: Dim intSalaries() As Integer. I'm new to this and taking an advanced visual basic programming course on line and struggling. Any help will be appreciated.
Jump to Post
Note that this does no error checking - it assumes that all of the strings represent numbers.
Dim strings() As String = System.IO.File.ReadAllLines("D:\temp\test.txt") Dim numbers(UBound(strings)) As Integer For i = 0 To UBound(strings) numbers(i) = CInt(strings(i)) Next
A version that checks but does not strictly …
Jump to Post
You can use the second form (List). Just replace intSalaries.Length with intSalaries.Count as in
Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click ' displays the salary amount associated with a code Dim intSalaries As New List(Of Integer) For Each line As String …
All 7 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.