VB列表内循环问题! ListBox内有N个项目,这个是不固定的。比如有3个项目 “青菜”,“紫菜”,“白菜”。 我想要的结果是 每个项目要这样配搭 每次要10个项目组合 比如 “青菜”10个 这是一个 “青菜”9 + “紫菜”1 10个 “青菜” 8 + “紫菜” 1 + “白菜” 1 =10 每个项目都要这样循环 应该有重复的结果,能考虑再内更好! 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不就是 a个青菜,b个紫菜,c个白菜, 要求a+b+c=10的 a、b、c组合吗?这比分硬币那个简单多了 A= 0 TO 10 B= 0 TO 10 C= 0 TO 10 IF A+B+C=10 THEN DEBUG.PRINT A & "+" & B & "+" & C & "=" & (A+B+C) EXIT FOR END IF NEXT NEXTNEXT3从循环,满足A+B+C=10即可 楼上的程序可以改一下,,循环未必只有三层,,说不定又有什么菜出来呢 ^_^而且可以判断 a+b+c...>0的时候 退出循环 Option ExplicitPrivate Sub Command1_Click() Dim str As String Dim strarr() As String Dim lens() As Integer Dim leng As Integer Dim i As Integer Dim j As Integer Dim k As Integer 'Init leng = 10 str = "青菜,紫菜,白菜" strarr = Split(str, ",") ReDim lens(UBound(strarr)) lens(0) = leng For i = 1 To UBound(lens) lens(i) = 0 Next Text1.Text = "" 'Start Do For i = 0 To UBound(strarr) Text1.Text = Text1.Text & strarr(i) & " " & lens(i) & " ," Next Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & " ;" & vbCrLf For i = UBound(lens) To LBound(lens) Step -1 If lens(i) = 0 Then Else If i < UBound(lens) Then lens(i) = lens(i) - 1 lens(i + 1) = lens(i + 1) + 1 For j = i + 2 To UBound(lens) lens(i + 1) = lens(i + 1) + lens(j) lens(j) = 0 Next Else For j = UBound(lens) - 1 To LBound(lens) Step -1 If lens(j) > 0 Then lens(j) = lens(j) - 1 lens(j + 1) = lens(j + 1) + 1 For k = j + 2 To UBound(lens) lens(j + 1) = lens(j + 1) + lens(k) lens(k) = 0 Next Exit For End If Next End If Exit For End If Next If lens(UBound(lens)) = leng Then Exit Do 'DoEvents Loop For i = 0 To UBound(strarr) Text1.Text = Text1.Text & strarr(i) & " " & lens(i) & " ," Next Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & " ;" & vbCrLfEnd Sub 水晶报表记录集的问题 VB6里怎么编写可以带参数的exe vb数组赋值得问题?请帮忙 本人想动态创建一个下拉菜单,谁有源代码,给看看 请教怎么用vb代码实现在word菜单中的"文件另存为"的功能,即:打开存储选择窗口,选择保存位置后自动保存. 挥汗~跳楼~大出血!!大结局! 散散散散散散分!!!!!(急!) 关于VB连接access数据库并通过treeview控件生成三层结构目录问题 谁会在VB中使用Direct play8?请赐教! 在vb中怎样利用sql排序 大家快来看看吧 如何创建一个以变量名的方式来命名的文本文档? VB中如何读写CSV文件?请给出例子代码,谢谢.
B= 0 TO 10
C= 0 TO 10
IF A+B+C=10 THEN
DEBUG.PRINT A & "+" & B & "+" & C & "=" & (A+B+C)
EXIT FOR
END IF
NEXT
NEXT
NEXT3从循环,满足A+B+C=10即可
Dim str As String
Dim strarr() As String
Dim lens() As Integer
Dim leng As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
'Init
leng = 10
str = "青菜,紫菜,白菜"
strarr = Split(str, ",")
ReDim lens(UBound(strarr))
lens(0) = leng
For i = 1 To UBound(lens)
lens(i) = 0
Next
Text1.Text = ""
'Start
Do
For i = 0 To UBound(strarr)
Text1.Text = Text1.Text & strarr(i) & " " & lens(i) & " ,"
Next
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & " ;" & vbCrLf
For i = UBound(lens) To LBound(lens) Step -1
If lens(i) = 0 Then
Else
If i < UBound(lens) Then
lens(i) = lens(i) - 1
lens(i + 1) = lens(i + 1) + 1
For j = i + 2 To UBound(lens)
lens(i + 1) = lens(i + 1) + lens(j)
lens(j) = 0
Next
Else
For j = UBound(lens) - 1 To LBound(lens) Step -1
If lens(j) > 0 Then
lens(j) = lens(j) - 1
lens(j + 1) = lens(j + 1) + 1
For k = j + 2 To UBound(lens)
lens(j + 1) = lens(j + 1) + lens(k)
lens(k) = 0
Next
Exit For
End If
Next
End If
Exit For
End If
Next If lens(UBound(lens)) = leng Then Exit Do
'DoEvents
Loop
For i = 0 To UBound(strarr)
Text1.Text = Text1.Text & strarr(i) & " " & lens(i) & " ,"
Next
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & " ;" & vbCrLfEnd Sub