VB数组问题: Text1.text写入任意几个数字(3-9个都行)比如输入7个1234567,或者8个23456789点击按钮得到 10
Text1.text写入任意几个数字(3-9个都行)比如输入7个1234567,或者8个23456789点击按钮得到每个数组组成三位数,并从小到大排列,中间是空格。比如1...
Text1.text写入任意几个数字(3-9个都行)比如输入7个1234567,或者8个23456789点击按钮得到
每个数组组成三位数,并从小到大排列,中间是空格。比如1234567 那么组成的123 124 125 126 127 134 135......
text2.text即点击按钮后得到123 124 125 126 127 134 135......(注意要从小至大的数字排列顺序)
代码错误。没有的数都组合出来了,有的却没有 展开
每个数组组成三位数,并从小到大排列,中间是空格。比如1234567 那么组成的123 124 125 126 127 134 135......
text2.text即点击按钮后得到123 124 125 126 127 134 135......(注意要从小至大的数字排列顺序)
代码错误。没有的数都组合出来了,有的却没有 展开
4个回答
展开全部
Option Explicit
Private Sub Command1_Click()
Dim a(10) As Long, aMax As Long, i As Long, j As Long, k As Long
Dim s As String, t As Long
s = Text1.Text
For i = 1 To Len(s)
a(i - 1) = Mid$(s, i, 1)
aMax = i - 1
Next i
For i = 0 To aMax - 1
j = i + 1
t = a(j)
Do Until j < 1
If a(j - 1) > t Then
a(j) = a(j - 1)
j = j - 1
Else
Exit Do
End If
Loop
a(j) = t
Next i
s = ""
For i = 0 To aMax
For j = 0 To aMax
For k = 0 To aMax
If a(i) > 0 And i <> j And i <> k And j <> k Then s = s & a(i) & a(j) & a(k) & " "
Next k
Next j
Next i
Text2.Text = s
End Sub
Private Sub Command1_Click()
Dim a(10) As Long, aMax As Long, i As Long, j As Long, k As Long
Dim s As String, t As Long
s = Text1.Text
For i = 1 To Len(s)
a(i - 1) = Mid$(s, i, 1)
aMax = i - 1
Next i
For i = 0 To aMax - 1
j = i + 1
t = a(j)
Do Until j < 1
If a(j - 1) > t Then
a(j) = a(j - 1)
j = j - 1
Else
Exit Do
End If
Loop
a(j) = t
Next i
s = ""
For i = 0 To aMax
For j = 0 To aMax
For k = 0 To aMax
If a(i) > 0 And i <> j And i <> k And j <> k Then s = s & a(i) & a(j) & a(k) & " "
Next k
Next j
Next i
Text2.Text = s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.计算长度
2.拆分为单字节数组,
3.数组排序
4.数组组合为数字
2.拆分为单字节数组,
3.数组排序
4.数组组合为数字
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
zf = Text1.Text
sz = Len(zf)
dzfc = ""
For i = 1 To sz - 2
For j = i + 1 To sz - 1
For k = j + 1 To sz
dzfc = dzfc & " " & Trim(i) & Trim(j) & Trim(k)
Next k
Next j
Next i
Text1.Text = dzfc
End Sub
zf = Text1.Text
sz = Len(zf)
dzfc = ""
For i = 1 To sz - 2
For j = i + 1 To sz - 1
For k = j + 1 To sz
dzfc = dzfc & " " & Trim(i) & Trim(j) & Trim(k)
Next k
Next j
Next i
Text1.Text = dzfc
End Sub
更多追问追答
追问
首先谢谢你的回答。我试过了,你写的这段代码只对特殊的数字管用,只能对12345,全是顺序排列是数字管用,对于03579,01356789,145789等你写的公式就不管用了,请认真看下我的问题。我的要求是(任意写入3-9个数字,每个数组组成三位数,并从小到大排列,中间是空格。)
追答
有上面作基础,下面仅仅作一下排序就行了,排序是各种语言一开始都要学的,我相信你应该会的吧?
Private Sub Command1_Click()
Dim Szss() As String
Dim Szs() As Integer
zf = Text1.Text
Sz = Len(zf)
dzfc = ""
For i = 1 To Sz - 2
For j = i + 1 To Sz - 1
For k = j + 1 To Sz
dzfc = dzfc & " " & Trim(i) & Trim(j) & Trim(k)
Next k
Next j
Next i
Szss = Split(dzfc, " ")
ReDim Szs(UBound(Szss)) As Integer
For i = 0 To UBound(Szs)
Szs(i) = Val(Szss(i))
Next i
For i = 0 To UBound(Szs) - 1
For j = i + 1 To UBound(Szs)
If Szs(j) < Szs(i) Then
intt = Szs(j)
Szs(j) = Szs(i)
Szs(i) = intt
End If
Next j
Next i
dzfc = ""
For i = 0 To UBound(Szs)
dzfc = dzfc & Szs(i) & " "
Next i
Text1.Text = dzfc
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上正解..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询