|
分類:[VB.NET/VB2005 以降]
If k1 = 1 Then
Randomize()
1: x1 = Int(Rnd() * n1)
If sd1_1(x1).s3 = 2 Or sd1_1(x1).s1 = "" Then GoTo 1
Label1.Text = sd1_1(x1).s1
2: x2 = Int(Rnd() * n1)
If x2 = x1 Or sd1_1(x2).s3 = 1 Or sd1_1(x2).s1 = "" Then GoTo 2
Label2.Text = sd1_1(x2).s1
3: x3 = Int(Rnd() * n1)
If x3 = x1 Or sd1_1(x3).s3 = 1 Or sd1_1(x3).s1 = "" Then GoTo 3
If x3 = x2 Or sd1_1(x3).s3 = 1 Or sd1_1(x3).s1 = "" Then GoTo 3
Label3.Text = sd1_1(x3).s1
4: x4 = Int(Rnd() * n1)
If x4 = x1 Or sd1_1(x4).s3 = 1 Or sd1_1(x4).s1 = "" Then GoTo 4
If x4 = x2 Or sd1_1(x4).s3 = 1 Or sd1_1(x4).s1 = "" Then GoTo 4
If x4 = x3 Or sd1_1(x4).s3 = 1 Or sd1_1(x4).s1 = "" Then GoTo 4
Label4.Text = sd1_1(x4).s1
End If
を 簡略化させようと思い、以下のように書き直したのですが、うまくラベル表示されません。
どこをどう直せばよいでしょうか。アドバイスお願いします。
If k1 = 1 Then
Static n(,) = {{2, 1, 1, 1}, {1, 2, 1, 1}, {1, 1, 2, 1}, {1, 1, 1, 2}, {1, 2, 2, 2}, {2, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}}
Dim al As New List(Of Integer)
Dim x As Integer
Randomize()
For i = 1 To 4
Do
x = Int(Rnd() * n0)
Loop While al.Contains(x) Or sd1_1(x).s4 = "済" Or sd1_1(x).s1 = "" Or sd1_1(x1).s3 = n(k1 - 1, 0) Or sd1_1(x2).s3 = n(k1 - 1, 1) Or _
sd1_1(x3).s3 = n(k1 - 1, 2) Or sd1_1(x4).s3 = n(k1 - 1, 3)
al.Add(x)
CType(Controls("Label" & i.ToString()), Label).Text = sd1_1(x).s1
Next
x1 = al(0)
x2 = al(1)
x3 = al(2)
x4 = al(3)
end if
|