假定有6个数字,每个数字从1——33,现在想在TEXT1中给出任意一个数字,算这6个数字相加后值为指定数字的组合情况!写代码如下,但一运行就未响应!请给予指点!
Private Sub Command1_Click()
a = 1
Do Until a = 34
b = 1
Do Until b = 34
If b = a Then
b = b + 1
End If
c = 1
Do Until c = 34
If c = b Then
c = c + 1
End If
If c - 1 = b And b - 1 = a Then
c = c + 1
End If
d = 1
Do Until d = 34
If d = c Then
d = d + 1
End If
e = 1
Do Until e = 34
If e = d Then
e = e + 1
End If
f = 1
Do Until f = 34
If f = e Then
f = f + 1
End If
zhi = a + b + c + d + e + f
If zhi = Int(Text1.Text) Then
List1.AddItem a & " " & b & " " & c & " " & d & " " & e & " " & f
End If
f = f + 1
Loop
e = e + 1
Loop
d = d + 1
Loop
c = c + 1
Loop
b = b + 1
Loop
a = a + 1
LoopEnd Sub
Private Sub Command1_Click()
a = 1
Do Until a = 34
b = 1
Do Until b = 34
If b = a Then
b = b + 1
End If
c = 1
Do Until c = 34
If c = b Then
c = c + 1
End If
If c - 1 = b And b - 1 = a Then
c = c + 1
End If
d = 1
Do Until d = 34
If d = c Then
d = d + 1
End If
e = 1
Do Until e = 34
If e = d Then
e = e + 1
End If
f = 1
Do Until f = 34
If f = e Then
f = f + 1
End If
zhi = a + b + c + d + e + f
If zhi = Int(Text1.Text) Then
List1.AddItem a & " " & b & " " & c & " " & d & " " & e & " " & f
End If
f = f + 1
Loop
e = e + 1
Loop
d = d + 1
Loop
c = c + 1
Loop
b = b + 1
Loop
a = a + 1
LoopEnd Sub
FROM table1 as a,table2 as b,table3 as c,table4
as d,table5 as e,table6 as f
WHERE a.f1+b.f1+c.f1+d.f1+e.f1+f.f1 = 200(你指定的数)
AND a.f1>=b.f1 AND b.f1>=c.f1 AND c.f1>=d.f1 AND
d.f1>=e.f1 AND e.f1>=f.f1'后面加句
ORDER BY a.f1 DESC,b.f1 DESC,c.f1 DESC,d.f1
DESC,e.f1,f,f1 DESC
更好看。^_^
'加个DoEvents
DoEvents
a = 1
Private Sub Command1_Click()
bStop = False 'Nomally run
a = 1
Do Until a = 34
b = 1
Do Until b = 34
If b = a Then
b = b + 1
End If
c = 1
Do Until c = 34
If c = b Then
c = c + 1
End If
If c - 1 = b And b - 1 = a Then
c = c + 1
End If
d = 1
Do Until d = 34
If d = c Then
d = d + 1
End If
e = 1
Do Until e = 34
If e = d Then
e = e + 1
End If
f = 1
Do Until f = 34
If f = e Then
f = f + 1
End If
zhi = a + b + c + d + e + f
If zhi = Int(Text1.Text) Then
List1.AddItem a & " " & b & " " & c & " " & d & " " & e & " " & f
End If
f = f + 1
'*****************************
List1.Refresh
DoEvents
If bStop Then Goto exitsub
'*****************************
Loop
e = e + 1
Loop
d = d + 1
Loop
c = c + 1
Loop
b = b + 1
Loop
a = a + 1
Loop
exitsub:
End SubPrivate Sub Command2_Click()
bStop = True
End If应该能中止。
你共有 6 层循环,应该执行 34 的 6 次方。 如果 1 毫秒执行一次公式运算,需要 1544804 秒,就是 17 天零 21 小时。