-1

到目前为止,这就是我为 Waterglen 解决方案所拥有的。我有点迷失了如何调用数组并用 0 定义所有内容去 lbl 无处可去。任何带 1 的东西都会先进入 lblfirst。

这是书中问题的图片。 http://imgur.com/a/YTNEX

提前感谢您的帮助。

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
4

1 回答 1

0

种族可能应该是 Int16 或 Int32 ,因为你不能有分数比赛或分数位置。

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]
于 2013-03-25T02:05:39.677 回答