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:
25000
35000
55000
70000
80200
90500
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.
benscomputers
0
Newbie Poster
Recommended Answers
Jump to PostNote 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 PostYou 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
Reverend Jim
4,678
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
benscomputers
0
Newbie Poster
Reverend Jim
4,678
Hi, I'm Jim, one of DaniWeb's moderators.
Moderator
Featured Poster
benscomputers
0
Newbie Poster
TnTinMN
418
Practically a Master Poster
benscomputers
0
Newbie Poster
jeremy.lawrence.7587
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.