vb排列组合问题
有text1、text2、text3、text4在里边输入内容如何将里边的内容随意组合并将各种组合方式存储在当前文件夹得txt文件里...
有text1、text2、text3、text4 在里边输入内容 如何将里边的内容随
意组合 并将各种组合方式存储在当前文件夹得txt文件里 展开
意组合 并将各种组合方式存储在当前文件夹得txt文件里 展开
1个回答
展开全部
添加4个text和一个command按钮:
Function Wrtxt(s As String)
Open App.Path & "\组合.txt" For Output As #1
Print #1, s & vbCrLf
Close #1
End Function
Private Sub Command1_Click()
Dim a As Variant
Dim Zmax As Integer
Dim jstr As String
Dim i As Integer, n As Integer, m As Integer, x As Integer, j As Integer, k As Integer
Me.Visible = False
a = Array(Text1.Text, Text2.Text, Text3.Text, Text4.Text)
For i = 0 To UBound(a) '1
jstr = jstr & vbCrLf & a(i)
Zmax = Zmax + 1
For n = 0 To UBound(a) '2
If n <> i Then
jstr = jstr & vbCrLf & a(i) & a(n)
Zmax = Zmax + 1
For m = 0 To UBound(a) '3
If m <> n And m <> i Then
jstr = jstr & vbCrLf & a(i) & a(n) & a(m)
Zmax = Zmax + 1
For x = 0 To UBound(a) '4
If x <> i And x <> n And x <> m Then
jstr = jstr & vbCrLf & a(i) & a(n) & a(m) & a(x)
Zmax = Zmax + 1
End If
Next x
End If
Next m
End If
Next n
Next i
Wrtxt jstr
MsgBox "共有组合" & Zmax & Chr(13) & "结果已生成txt文件:" & App.Path & "\组合.txt", vbInformation, "【组合】" & Chr(13)
Unload Me
End Sub
Function Wrtxt(s As String)
Open App.Path & "\组合.txt" For Output As #1
Print #1, s & vbCrLf
Close #1
End Function
Private Sub Command1_Click()
Dim a As Variant
Dim Zmax As Integer
Dim jstr As String
Dim i As Integer, n As Integer, m As Integer, x As Integer, j As Integer, k As Integer
Me.Visible = False
a = Array(Text1.Text, Text2.Text, Text3.Text, Text4.Text)
For i = 0 To UBound(a) '1
jstr = jstr & vbCrLf & a(i)
Zmax = Zmax + 1
For n = 0 To UBound(a) '2
If n <> i Then
jstr = jstr & vbCrLf & a(i) & a(n)
Zmax = Zmax + 1
For m = 0 To UBound(a) '3
If m <> n And m <> i Then
jstr = jstr & vbCrLf & a(i) & a(n) & a(m)
Zmax = Zmax + 1
For x = 0 To UBound(a) '4
If x <> i And x <> n And x <> m Then
jstr = jstr & vbCrLf & a(i) & a(n) & a(m) & a(x)
Zmax = Zmax + 1
End If
Next x
End If
Next m
End If
Next n
Next i
Wrtxt jstr
MsgBox "共有组合" & Zmax & Chr(13) & "结果已生成txt文件:" & App.Path & "\组合.txt", vbInformation, "【组合】" & Chr(13)
Unload Me
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询