VB字符串组合
Text1和Text2两个Textbox,Text1指定一些字符(包括数字、字母和符号),Text2显示这些字符所有的组合(一个组合一行)不能重复...
Text1和Text2两个Textbox,Text1指定一些字符(包括数字、字母和符号),Text2显示这些字符所有的组合(一个组合一行)不能重复
展开
8个回答
展开全部
TEXT没有分行的功能,但是你可以在输出的时候让每种组合用逗号隔开然后到WORD里面用分行替换逗号来实现。或者换一个增强功能的TEXT控件,用ctrl+t调出找到一个TEXT打头的一个,名字忘了,它的用法跟TEXT基本相同,同时能够加入滚动条。
在功能实现方面分为以下几步:
1.统计TEXT1里面有多少个字符,一个一个存到数组里面,数组上限为TEXT1的字符数。
2.在存储字符的时候比较是否跟数组前面部分的数值相同,相同则转到存储下一个,不同则存储该字符。
3.用排列统计的知识,从1个,2个,3个......的组合一个一个来,因为你的数值里面没有重复的字符,所以你按照次序来进行排列生成的结果不会有重复的。比如:a(1)a(2),a(1)a(3),a(1)a(4)...,a(2)a(1),a(2)a(3),a(2)a(4)。这部分用循环来实现。
在功能实现方面分为以下几步:
1.统计TEXT1里面有多少个字符,一个一个存到数组里面,数组上限为TEXT1的字符数。
2.在存储字符的时候比较是否跟数组前面部分的数值相同,相同则转到存储下一个,不同则存储该字符。
3.用排列统计的知识,从1个,2个,3个......的组合一个一个来,因为你的数值里面没有重复的字符,所以你按照次序来进行排列生成的结果不会有重复的。比如:a(1)a(2),a(1)a(3),a(1)a(4)...,a(2)a(1),a(2)a(3),a(2)a(4)。这部分用循环来实现。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'两个TextBox,一个CommandButton
'设置TextBox2的Multiline=True,ScrollBars=Vertical
Dim k() As String, length As Integer
Private Sub Command1_Click()
ptn = Text1.Text
length = Len(ptn)
ReDim k(0)
combine (ptn)
Text2.Text = Join(k, vbCrLf)
End Sub
Sub combine(ByVal s As String)
If Len(s) = 0 Then
If UBound(k) <> 0 Then k(UBound(k)) = Mid(k(UBound(k) - 1), 1, length - Len(k(UBound(k)))) & k(UBound(k))
ReDim Preserve k(UBound(k) + 1)
Exit Sub
End If
For i = 1 To Len(s)
t = Mid(s, i, 1)
k(UBound(k)) = k(UBound(k)) & t
combine (Replace(s, t, ""))
Next
End Sub
'设置TextBox2的Multiline=True,ScrollBars=Vertical
Dim k() As String, length As Integer
Private Sub Command1_Click()
ptn = Text1.Text
length = Len(ptn)
ReDim k(0)
combine (ptn)
Text2.Text = Join(k, vbCrLf)
End Sub
Sub combine(ByVal s As String)
If Len(s) = 0 Then
If UBound(k) <> 0 Then k(UBound(k)) = Mid(k(UBound(k) - 1), 1, length - Len(k(UBound(k)))) & k(UBound(k))
ReDim Preserve k(UBound(k) + 1)
Exit Sub
End If
For i = 1 To Len(s)
t = Mid(s, i, 1)
k(UBound(k)) = k(UBound(k)) & t
combine (Replace(s, t, ""))
Next
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你试试我下面的程序,不知道对你有没有帮助(虽然没有实现你要的功能)
Private Sub Command1_Click()
Dim EndNum as integer,SelectNum as Integer
EndNum=10
SelectNum=5
Open "c:\a.txt" For Output As #1 '这里可以改成你想要输出的文件
NFormM 1, EndNum, SelectNum
Close #1
MsgBox "输出完毕"
End Sub
Function NFormM(ByVal iStart As Integer, iEnd As Integer, Num As Integer, _
Optional Str As String)
Dim i As Integer
If Num = 0 Then
Print #1, Str
Else
For i = iStart To iEnd
DoEvents
NFormM i + 1, iEnd, Num - 1, Str & i & ","
Next
End If
End Function
Private Sub Command1_Click()
Dim EndNum as integer,SelectNum as Integer
EndNum=10
SelectNum=5
Open "c:\a.txt" For Output As #1 '这里可以改成你想要输出的文件
NFormM 1, EndNum, SelectNum
Close #1
MsgBox "输出完毕"
End Sub
Function NFormM(ByVal iStart As Integer, iEnd As Integer, Num As Integer, _
Optional Str As String)
Dim i As Integer
If Num = 0 Then
Print #1, Str
Else
For i = iStart To iEnd
DoEvents
NFormM i + 1, iEnd, Num - 1, Str & i & ","
Next
End If
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Text1每项以逗号分隔开
Private Sub Command1_Click()
Dim arr
temparr = Split(Text1.Text, ",")
m = UBound(temparr) + 1
ReDim arr(m - 1, 0)
For i = 0 To m - 1
arr(i, 0) = temparr(i)
Next i
For n = 2 To m
ReDim Preserve arr(m - 1, n * (a + 1) - 1)
For i = 0 To a
For k = 1 To n - 1
a = a + 1
For j = 0 To n - k - 2
arr(j, a) = arr(j, i)
Next j
arr(n - k - 1, a) = arr(n - 1, i)
For j = n - k To n - 1
arr(j, a) = arr(j - 1, i)
Next j
For j = n To m - 1
arr(j, a) = arr(j, i)
Next j
Next k
Next i
Next n
For i = 0 To UBound(arr, 2)
For j = 0 To UBound(arr, 1)
s = s & arr(j, i) & ","
Next j
s = s & vbCrLf
Next i
Text2.Text = s
End Sub
Private Sub Command1_Click()
Dim arr
temparr = Split(Text1.Text, ",")
m = UBound(temparr) + 1
ReDim arr(m - 1, 0)
For i = 0 To m - 1
arr(i, 0) = temparr(i)
Next i
For n = 2 To m
ReDim Preserve arr(m - 1, n * (a + 1) - 1)
For i = 0 To a
For k = 1 To n - 1
a = a + 1
For j = 0 To n - k - 2
arr(j, a) = arr(j, i)
Next j
arr(n - k - 1, a) = arr(n - 1, i)
For j = n - k To n - 1
arr(j, a) = arr(j - 1, i)
Next j
For j = n To m - 1
arr(j, a) = arr(j, i)
Next j
Next k
Next i
Next n
For i = 0 To UBound(arr, 2)
For j = 0 To UBound(arr, 1)
s = s & arr(j, i) & ","
Next j
s = s & vbCrLf
Next i
Text2.Text = s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
textbox没有分行的功能
需要用到其他的控件
能不能说的具体点
放点代码看下
需要用到其他的控件
能不能说的具体点
放点代码看下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询