我设计的一个小程序,但总是不执行第二个循环,求大虾们帮帮忙
Private Sub Command1_Click()
Dim X As Single, Y As Single, z As Single
Dim a(41, 1) As Single
Dim i As Integer
Dim j As Integer
a(0, 0) = 60.5: a(0, 1) = 5
a(1, 0) = 60.6: a(1, 1) = 16
a(2, 0) = 60.7: a(2, 1) = 28
a(3, 0) = 60.8: a(3, 1) = 39
a(4, 0) = 60.9: a(4, 1) = 51
a(5, 0) = 61#: a(5, 1) = 62
a(6, 0) = 61.1: a(6, 1) = 90
a(7, 0) = 61.2: a(7, 1) = 120
a(8, 0) = 61.3: a(8, 1) = 150
a(9, 0) = 61.4: a(9, 1) = 190
a(10, 0) = 61.5: a(10, 1) = 235
a(11, 0) = 61.6: a(11, 1) = 265
a(12, 0) = 61.7: a(12, 1) = 300
a(13, 0) = 61.8: a(13, 1) = 385
a(14, 0) = 61.9: a(14, 1) = 480
a(15, 0) = 62#: a(15, 1) = 579
a(16, 0) = 62.1: a(16, 1) = 660
a(17, 0) = 62.2: a(17, 1) = 750
a(18, 0) = 62.3: a(18, 1) = 850
a(19, 0) = 62.4: a(19, 1) = 990
a(20, 0) = 62.5: a(20, 1) = 1084
a(21, 0) = 62.6: a(21, 1) = 1200
a(22, 0) = 62.7: a(22, 1) = 1320
a(23, 0) = 62.8: a(23, 1) = 1450
a(24, 0) = 62.9: a(24, 1) = 1590
a(25, 0) = 63#: a(25, 1) = 1735
a(26, 0) = 63.1: a(26, 1) = 1890
a(27, 0) = 63.2: a(27, 1) = 2050
a(28, 0) = 63.3: a(28, 1) = 2200
a(29, 0) = 63.4: a(29, 1) = 2350
a(30, 0) = 63.5: a(30, 1) = 2538
a(31, 0) = 63.6: a(31, 1) = 2700
a(32, 0) = 63.7: a(32, 1) = 2870
a(33, 0) = 63.8: a(33, 1) = 3050
a(34, 0) = 63.9: a(34, 1) = 3270
a(35, 0) = 64#: a(35, 1) = 3489
a(36, 0) = 64.1: a(36, 1) = 3270
a(37, 0) = 64.2: a(37, 1) = 3950
a(38, 0) = 64.3: a(38, 1) = 4180
a(39, 0) = 64.4: a(39, 1) = 4420
a(40, 0) = 64.5: a(40, 1) = 4653
a(41, 0) = 64.51: a(41, 1) = 4654
X = Val(Text1.Text)
If X < a(0, 0) Or X > a(41, 0) Then
MsgBox "输入数据错误", vbOKOnly, "错误"
Else
Do
z = a(i + 1, j)
If X <= z Then
Print a(i, j); a(i, j + 1); a(i + 1, j); a(i + 1, j + 1)
Y = (a(i + 1, j + 1) - a(i, j + 1)) * (X - a(i, j)) * 10 + a(i, j + 1)
Print a(i + 1, j + 1) - a(i, j + 1)
Print X - a(i, j)
Y = Format(Y, "0")
Print Y
Print i + 1, j
Text2.Text = Str(Y)
End If
i = i + 1
If X = 64.5 Then
Text2.Text = 4653
End If
Loop Until X - z < 0 Or X = 64.5
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command3_Click()
Dim X As Single, Y As Single, z As Single, o As Single
Dim a(46, 1) As Single
Dim i As Integer
Dim j As Integer
a(0, 0) = 58.35: a(0, 1) = 1
a(1, 0) = 58.85: a(1, 1) = 13
a(2, 0) = 59.35: a(2, 1) = 52
a(3, 0) = 59.4: a(3, 1) = 60
a(4, 0) = 59.5: a(4, 1) = 85
a(5, 0) = 59.6: a(5, 1) = 110
a(6, 0) = 59.7: a(6, 1) = 132
a(7, 0) = 59.8: a(7, 1) = 155
a(8, 0) = 59.85: a(8, 1) = 168
a(9, 0) = 59.9: a(9, 1) = 185
a(10, 0) = 60#: a(10, 1) = 230
a(11, 0) = 60.1: a(11, 1) = 280
a(12, 0) = 60.2: a(12, 1) = 325
a(13, 0) = 60.3: a(13, 1) = 370
a(14, 0) = 60.35: a(14, 1) = 394
a(15, 0) = 60.4: a(15, 1) = 425
a(16, 0) = 60.5: a(16, 1) = 490
a(17, 0) = 60.6: a(17, 1) = 560
a(18, 0) = 60.7: a(18, 1) = 625
a(19, 0) = 60.8: a(19, 1) = 695
a(20, 0) = 60.85: a(20, 1) = 728
a(21, 0) = 60.9: a(21, 1) = 770
a(22, 0) = 61#: a(22, 1) = 857
a(23, 0) = 61.1: a(23, 1) = 943
a(24, 0) = 61.2: a(24, 1) = 1030
a(25, 0) = 61.3: a(25, 1) = 1115
a(26, 0) = 61.4: a(26, 1) = 1210
a(27, 0) = 61.5: a(27, 1) = 1315
a(28, 0) = 61.6: a(28, 1) = 1420
a(29, 0) = 61.7: a(29, 1) = 1520
a(30, 0) = 61.8: a(30, 1) = 1620
a(31, 0) = 61.85: a(31, 1) = 1673
a(32, 0) = 61.9: a(32, 1) = 1730
a(33, 0) = 62#: a(33, 1) = 1850
a(34, 0) = 62.1: a(34, 1) = 1960
a(35, 0) = 62.2: a(35, 1) = 2050
a(36, 0) = 62.3: a(36, 1) = 2170
a(37, 0) = 62.4: a(37, 1) = 2320
a(38, 0) = 62.5: a(38, 1) = 2435
a(39, 0) = 62.6: a(39, 1) = 2550
a(40, 0) = 62.7: a(40, 1) = 2685
a(41, 0) = 62.8: a(41, 1) = 2825
a(42, 0) = 62.85: a(41, 1) = 2894
a(43, 0) = 62.86: a(41, 1) = 2895
X = Val(Text3.Text)
If X < a(0, 0) Or X > a(41, 0) Then
MsgBox "输入数据错误", vbOKOnly, "错误"
Else
If a(2, 0) < X < a(3, 0) Or a(7, 0) < X < a(9, 0) Or a(13, 0) < X < a(15, 0) Or a(19, 0) < X < a(21, 0) Or a(30, 0) < X < a(32, 0) Then
Do
z = a(i + 1, j)
If X <= z Then
Print a(i, j); a(i, j + 1); a(i + 1, j); a(i + 1, j + 1)
Y = (a(i + 1, j + 1) - a(i, j + 1)) * (X - a(i, j)) * 20 + a(i, j + 1)
Print a(i + 1, j + 1) - a(i, j + 1)
Print X - a(i, j)
Y = Format(Y, "0")
Print Y
Print i + 1, j
Text4.Text = Str(Y)
End If
i = i + 1
If X = 62.85 Then
Text4.Text = 2894
End If
Loop Until X - z < 0 Or X = 62.85
Else
Do
o = a(i + 1, j)
If X <= o Then
Print a(i, j); a(i, j + 1); a(i + 1, j); a(i + 1, j + 1)
Y = (a(i + 1, j + 1) - a(i, j + 1)) * (X - a(i, j)) * 10 + a(i, j + 1)
Print a(i + 1, j + 1) - a(i, j + 1)
Print X - a(i, j)
Y = Format(Y, "0")
Print Y
Print i + 1, j
Text4.Text = Str(Y)
End If
i = i + 1
If X = 62.85 Then
Text4.Text = 2894
End If
Loop Until X - o < 0 Or X = 62.85
End If
End If
End Sub
Private Sub Command4_Click()
Text3.Text = ""
Text4.Text = ""
Cls
End Sub
Private Sub Command5_Click()
Dim X As Single, Y As Single, z As Single
Dim a(45, 1) As Single
Dim i As Integer
Dim j As Integer
a(0, 0) = 56.85: a(0, 1) = 0
a(1, 0) = 56.9: a(1, 1) = 1.17
a(2, 0) = 57#: a(2, 1) = 3.5
a(3, 0) = 57.1: a(3, 1) = 8.73
a(4, 0) = 57.2: a(4, 1) = 13.96
a(5, 0) = 57.3: a(5, 1) = 19.19
a(6, 0) = 57.35: a(6, 1) = 21.8
a(7, 0) = 57.4: a(7, 1) = 28.8
a(8, 0) = 57.5: a(8, 1) = 42.9
a(9, 0) = 57.6: a(9, 1) = 57
a(10, 0) = 57.7: a(10, 1) = 82.8
a(11, 0) = 57.8: a(11, 1) = 108.6
a(12, 0) = 57.85: a(12, 1) = 121.5
a(13, 0) = 57.95: a(13, 1) = 150
a(14, 0) = 58.05: a(14, 1) = 190
a(15, 0) = 58.15: a(15, 1) = 230
a(16, 0) = 58.25: a(16, 1) = 275
a(17, 0) = 58.35: a(17, 1) = 320.5
a(18, 0) = 58.45: a(18, 1) = 375
a(19, 0) = 58.55: a(19, 1) = 430
a(20, 0) = 58.65: a(20, 1) = 490
a(21, 0) = 58.75: a(21, 1) = 550
a(22, 0) = 58.85: a(22, 1) = 618.4
a(23, 0) = 58.95: a(23, 1) = 700
a(24, 0) = 59#: a(24, 1) = 735
a(25, 0) = 59.05: a(25, 1) = 770
a(26, 0) = 59.15: a(26, 1) = 850
a(27, 0) = 59.25: a(27, 1) = 940
a(28, 0) = 59.35: a(28, 1) = 1017.5
a(29, 0) = 59.45: a(29, 1) = 1130
a(30, 0) = 59.5: a(30, 1) = 1180
a(31, 0) = 59.55: a(31, 1) = 1230
a(32, 0) = 59.65: a(32, 1) = 1320
a(33, 0) = 59.75: a(33, 1) = 1420
a(34, 0) = 59.85: a(34, 1) = 1509
a(35, 0) = 59.95: a(35, 1) = 1620
a(36, 0) = 60.05: a(36, 1) = 1735
a(37, 0) = 60.15: a(37, 1) = 1845
a(38, 0) = 60.25: a(38, 1) = 1960
a(39, 0) = 60.35: a(39, 1) = 2083
a(40, 0) = 60.45: a(40, 1) = 2205
a(41, 0) = 60.55: a(41, 1) = 2330
a(42, 0) = 60.65: a(42, 1) = 2460
a(43, 0) = 60.75: a(43, 1) = 2600
a(44, 0) = 60.85: a(44, 1) = 2754
a(45, 0) = 60.75: a(45, 1) = 2755
X = Val(Text5.Text)
If X < a(0, 0) Or X > a(41, 0) Then
MsgBox "输入数据错误", vbOKOnly, "错误"
Else
If a(0, 0) < X < a(1, 0) Or a(5, 0) < X < a(7, 0) Or a(11, 0) < X < a(12, 0) Or a(23, 0) < X < a(25, 0) Or a(29, 0) < X < a(31, 0) Then
Do
z = a(i + 1, j)
If X <= z Then
Print a(i, j); a(i, j + 1); a(i + 1, j); a(i + 1, j + 1)
Y = (a(i + 1, j + 1) - a(i, j + 1)) * (X - a(i, j)) * 20 + a(i, j + 1)
Print a(i + 1, j + 1) - a(i, j + 1)
Print X - a(i, j)
Y = Format(Y, "0")
Print Y
Print i + 1, j
Text6.Text = Str(Y)
End If
i = i + 1
If X = 60.85 Then
Text6.Text = 2754
End If
Loop Until X - z < 0 Or X = 60.85
Else
Do
z = a(i + 1, j)
If X <= z Then
Print a(i, j); a(i, j + 1); a(i + 1, j); a(i + 1, j + 1)
Y = (a(i + 1, j + 1) - a(i, j + 1)) * (X - a(i, j)) * 10 + a(i, j + 1)
Print a(i + 1, j + 1) - a(i, j + 1)
Print X - a(i, j)
Y = Format(Y, "0")
Print Y
Print i + 1, j
Text6.Text = Str(Y)
End If
i = i + 1
If X = 60.85 Then
Text6.Text = 2754
End If
Loop Until X - z < 0 Or X = 60.85
End If
End If
End Sub
Private Sub Command6_Click()
Text5.Text = ""
Text6.Text = ""
End Sub
Private Sub Form_Load()
End Sub
我的设计思路是这样的,在text1、text3、text5上输入一个数据后,按命令按钮,
在超出数列范围时,提示错误。
在特定的区间,如a(0, 0) < X < a(1, 0) Or a(5, 0) < X < a(7, 0) Or a(11, 0) < X < a(12, 0) Or a(23, 0) < X < a(25, 0) Or a(29, 0) < X < a(31, 0)时,
执行Y = (a(i + 1, j + 1) - a(i, j + 1)) * (X - a(i, j)) * 20 + a(i, j + 1)。
在一般情况下,
执行Y = (a(i + 1, j + 1) - a(i, j + 1)) * (X - a(i, j)) * 10 + a(i, j + 1)。
也就是说在一般情况下,是特殊情况下的1/2。
求解。
[ 本帖最后由 scbbgs 于 2011-7-4 16:28 编辑 ]