two-dimensional array

dknoll

New member
Joined
Nov 11, 2005
Messages
2
Programming Experience
Beginner
I really need some help with this program. I have to load a text file into the form and then average the daily totals. Here is how it should look like a table:


(column headings)0:00 2:00 4:00 6:00 8:00 10:00 12:00 (etc.,up to 22:00)

Sun. 32 33 31 35 37 42 44 --- 39.25 (this is avg)

Mon. 33 32 31 33 33 32 31 --- 32.22

(etc. days are row headings -through the days of the week - numbers line up under column headings with average at end of row)


I have to load it at form load and use a For Next nested loop and put it into a list box.

Here is the code I have so far:

PublicClass EX611
Inherits System.Windows.Forms.Form

Dim intPollen(6, 11) AsShort




PrivateSub EX611_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load

Dim intHourCount AsInteger
Dim intDayCount AsInteger
Dim intDaySum AsInteger
Dim strItem AsString



FileOpen(1, CurDir() & "\pollen.txt", OpenMode.Input)

For intDayCount = 0 To 6

For intHourCount = 0 To 11

Input(1, intPollen(intDayCount, intHourCount))

intDaySum = intDaySum + intPollen(intDayCount, intHourCount)

strItem = strItem & vbTab &
CStr(intPollen(intDayCount, intHourCount)

Next intHourCount

lstEntries.Items.Add(strItem)

Next intDayCount

EndSub



It's not loading correctly and I don't know how to do the headings either. I've worked on this for hours. Please help.

My text file has entries like this:

32,33,31,35,37,42,44
 
I too had a hard time using more .NET methods than the old familier FileOpen types from the old VB days. I used a .split function since you advised your text file has the hour values in one line, each line being a day? Maybe I'm assuming too much. Anyway, the following reads the text file, one line at a time. Then it splits that line on the "," between values. Fills the current y value (Day) in the 2D array intPollen, as well as adds the x values (Hour) in intDaySum. It then adds them to a listbox.

VB.NET:
Dim reader As New StreamReader(Application.StartupPath & "\pollen.txt")
        Dim line, data() As String
        Dim intDayCount, intHourCount, intDaySum As Integer
        line = reader.ReadLine
        While Not line Is Nothing
            data = line.Split(",")
            intDaySum = 0
            For intHourCount = 0 To data.GetUpperBound(0)
                intPollen(intDayCount, intHourCount) = data(intHourCount)
                intDaySum += data(intHourCount)
            Next
            ListBox1.Items.Add(WeekdayName(intDayCount + 1, True) & vbTab & line & vbTab & intDaySum.ToString)
            intDayCount += 1
            line = reader.ReadLine
        End While
        reader.Close()
HTH,
Blokz
 
Thank you for answering me. I don't think it has to be very complicated and I have to work with the code I have. With the code I have in already, it reads the text file but all on one line. So first things first, how can I manipulate the code I already have, but have each line read to a separate line? For example, my text file is:

33,34,34,34,25
33,44,55,44,44

And I would like the list box to list those two on separate lines. Right now it reads:

33,34,34,34,25,33,44,55,44,44

Here is my code:

PrivateSub EX611_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load


Dim intDayCount, intHourCount AsInteger
Dim strItem AsString

FileOpen(1, CurDir() + "\pollen.txt", OpenMode.Input)

For intDayCount = 0 To 6

For intHourCount = 0 To 11

Input(1, intPollen(intDayCount, intHourCount))
strItem = strItem & vbTab &
CStr(intPollen(intDayCount, intHourCount))

Next intHourCount

Next intDayCount

lstEntries.Items.Add(strItem)

EndSub


I have to get this working first, then I'll worry about the headings and the totals. Thank you so much!
 
Back
Top