-1

This is what i have for the Waterglen Solution so far.. I'm kind of lost as to how to call on the array and define everything with a 0 goes to the lbl for no place. And anything with a 1 goes to the lblfirst.

Here is a picture of the problem from the book. https://i.stack.imgur.com/Pfj0v.jpg

Thanks for your help in advance.

Option Explicit On
Option Strict On
Option Infer Off

Public Class Form1
Private race(,) As Decimal = {{0, 1, 0, 3, 2}, {1, 0, 2, 0, 0}, {0, 3, 0, 1, 0}, {3, 2, 1, 0, 0}}

'Private horse() As String = {"Horse1", "Horse2", "Horse3", "Horse4"}

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
End Sub


Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click


End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ListBox1.Items.Add("Horse1")
    ListBox1.Items.Add("Horse2")
    ListBox1.Items.Add("Horse3")
    ListBox1.Items.Add("Horse4")
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    Dim SubScript As Integer = ListBox1.SelectedIndex


    lblFirst.Text = race(SubScript, 0).ToString("N0")
    lblSecond.Text = race(SubScript, 1).ToString("N0")
    lblThird.Text = race(SubScript, 2).ToString("N0")
    lblNoPlace.Text = race(SubScript, 3).ToString("N0")

End Sub
End Class
pnuts
  • 58,317
  • 11
  • 87
  • 139
mavrick951
  • 15
  • 3
  • Was asking for help not for you to do it for me... As you can see above i have something there showing that i am working on it right? – mavrick951 Mar 24 '13 at 22:34
  • Perhaps I was too hasty. – Sam Axe Mar 24 '13 at 23:50
  • I was just looking for help on how to call on the array and look for everything in the row that is a specific number. Right now as is i am calling on the array on column which isn't what i need it to do. I have googled my eyes out and tried a couple different solutions but can't get it to work. – mavrick951 Mar 24 '13 at 23:55
  • So you want a count of all the occurrences of a specific number in the array? Like, how many times the number 0 occurs in the array? – Sam Axe Mar 25 '13 at 00:32
  • Correct well in ' Private race(,) As Decimal = {{0, 1, 0, 3, 2}, {1, 0, 2, 0, 0}, {0, 3, 0, 1, 0}, {3, 2, 1, 0, 0}}' how many times in row 1 does 0 occur – mavrick951 Mar 25 '13 at 00:44

1 Answers1

0

race should probably be an Int16 or Int32 given that you can't have a fractional race or a fractional place.

Dim rowIndex As Int16 = 1
Dim count As Int16 = 0
Dim value As Int16 = 0

For columnIndex = 0 to race.GetLength(rowIndex) - 1
  If value = race(rowIndex)(columnIndex)
    count += 1
  End If
Next

'  count contains how many times [value] occurs in row [rowIndex]
Sam Axe
  • 33,313
  • 9
  • 55
  • 89