我对VB很新,我遇到了一些问题。我正在使用Repeat Until循环,如果我尝试将任何微小的复杂性放入其中,我的程序就会崩溃。我正在生成随机数。我已将问题隔离到以下循环,并删除了其他不影响它的代码。
ShowNO,Hidden,C,CA,R,RA,B,BA和所有B11等值被定义为整数。
Hidden仅限于HSB中的11-19范围,因此不能解决问题
Hidden = hsbDifficulty.Value * -1
If (Hidden = 11 Or 12) Then
RA = 5
CA = 5
BA = 5
End If
If (Hidden = 13 Or 14) Then
RA = 5
CA = 5
BA = 6
End If
If (Hidden = 15 Or 16 Or 17) Then
RA = 5
CA = 6
BA = 6
End If
If (Hidden = 18 Or 19) Then
RA = 6
CA = 6
BA = 6
End If
Randomize()
Do
Do
ShowNO = (Rnd() * 36)
Select Case ShowNO
Case Is = 0
B66 = 1
Case Is = 1
B11 = 1
Case Is = 2
B12 = 1
Case Is = 3
B13 = 1
Case Is = 4
B14 = 1
Case Is = 5
B15 = 1
Case Is = 6
B16 = 1
Case Is = 7
B21 = 1
Case Is = 8
B22 = 1
Case Is = 9
B23 = 1
Case Is = 10
B24 = 1
Case Is = 11
B25 = 1
Case Is = 12
B26 = 1
Case Is = 13
B31 = 1
Case Is = 14
B32 = 1
Case Is = 15
B33 = 1
Case Is = 16
B34 = 1
Case Is = 17
B35 = 1
Case Is = 18
B36 = 1
Case Is = 19
B41 = 1
Case Is = 20
B42 = 1
Case Is = 21
B43 = 1
Case Is = 22
B44 = 1
Case Is = 23
B45 = 1
Case Is = 24
B46 = 1
Case Is = 25
B51 = 1
Case Is = 26
B52 = 1
Case Is = 27
B53 = 1
Case Is = 28
B54 = 1
Case Is = 29
B55 = 1
Case Is = 30
B56 = 1
Case Is = 31
B61 = 1
Case Is = 32
B62 = 1
Case Is = 33
B63 = 1
Case Is = 34
B64 = 1
Case Is = 35
B65 = 1
Case Is = 36
B66 = 1
End Select
Loop Until (B11 + B12 + B13 + B14 + B15 + B16 + B21 + B22 + B23 + B24 + B25 + B26 + B31 + B32 + B33 + B34 + B35 + B36 + B41 + B42 + B43 + B44 + B45 + B46 + B51 + B52 + B53 + B54 + B55 + B56 + B61 + B62 + B63 + B64 + B65 + B66 = Hidden)
If (B11 + B12 + B13 + B14 + B15 + B16 > 0.9) Then
R = R + 1
End If
If (B21 + B22 + B23 + B24 + B25 + B26 > 0.9) Then
R = R + 1
End If
If (B31 + B32 + B33 + B34 + B35 + B36 > 0.9) Then
R = R + 1
End If
If (B41 + B42 + B43 + B44 + B45 + B46 > 0.9) Then
R = R + 1
End If
If (B51 + B52 + B53 + B54 + B55 + B56 > 0.9) Then
R = R + 1
End If
If (B61 + B62 + B63 + B64 + B65 + B66 > 0.9) Then
R = R + 1
End If
If (B11 + B21 + B31 + B41 + B51 + B61 > 0.9) Then
C = C + 1
End If
If (B12 + B22 + B32 + B42 + B52 + B62 > 0.9) Then
C = C + 1
End If
If (B13 + B23 + B33 + B43 + B53 + B63 > 0.9) Then
C = C + 1
End If
If (B14 + B24 + B34 + B44 + B54 + B64 > 0.9) Then
C = C + 1
End If
If (B15 + B25 + B35 + B45 + B55 + B65 > 0.9) Then
C = C + 1
End If
If (B16 + B26 + B36 + B46 + B56 + B66 > 0.9) Then
C = C + 1
End If
If (B11 + B12 + B13 + B21 + B22 + B23 > 0.9) Then
B = B + 1
End If
If (B31 + B32 + B33 + B41 + B42 + B43 > 0.9) Then
B = B + 1
End If
If (B51 + B52 + B53 + B61 + B62 + B63 > 0.9) Then
B = B + 1
End If
If (B14 + B15 + B16 + B24 + B25 + B26 > 0.9) Then
B = B + 1
End If
If (B34 + B35 + B36 + B44 + B45 + B46 > 0.9) Then
B = B + 1
End If
If (B54 + B55 + B56 + B64 + B65 + B66 > 0.9) Then
B = B + 1
End If
Loop Until (B > (BA - 1) And C > (CA - 1) And R > (RA - 1))
答案 0 :(得分:1)
如果您在VB .Net中阅读Select Case
的{{3}},您会发现自己错了:
Select Case ShowNo
'Use Case 0 Instead of Case Is = 0
Case 0
'Do some Stuff
End Select
另外,正如nabuchodonossor所提到的那样,If
在开始时并不好:
'Proper way to write this :
If Hidden = 11 Or Hidden = 12 Then
此外,如果你能给我们一个你认可的例外,我们或许可以帮助你。
答案 1 :(得分:0)
将整个事情重新安装到修复问题的数组中。可能是导致崩溃的大量变量。谢谢你的帮助。