vb中文本框可以输出的内容如何在列表框里输出?
我写了下面的一段代码,界面上有一个文本框控件,Multiline属性为True,Scrollbars属性为2,还有一个标签和一个命令按钮.运行一切正常,我现在的问题是把文...
我写了下面的一段代码,界面上有一个文本框控件,Multiline属性为True,Scrollbars属性为2,还有一个标签和一个命令按钮.运行一切正常,我现在的问题是把文本框改为列表框,要达到与文本框一样的效果,里面的每一个数都要以"00"格式显示.还有一个要求就是每行的数据要从小到大的顺序排列,代码该怎么写呢?谢谢!
Private Sub Command1_Click()
Dim a0() As Integer, a1() As Integer, x%, y$
y = InputBox("请输入a0数组元素个数", "输入数据", "5")
If Val(y) = 0 Or Val(y) = 1 Then Exit Sub
ReDim a0(1 To Val(y))
For x = 1 To UBound(a0)
y = InputBox("请输入a0数组第" & x & "个元素", "输入数据", "1")
If Val(y) = 0 Then Exit Sub
a0(x) = Val(y)
Next
y = InputBox("请输入a1数组元素个数", "输入数据", "4")
If Val(y) = 0 Or Val(y) = 1 Then Exit Sub
ReDim a1(1 To Val(y))
For x = 1 To UBound(a1)
y = InputBox("请输入a1数组第" & x & "个元素", "输入数据", "2")
If Val(y) = 0 Then Exit Sub
a1(x) = Val(y)
Next
Text1.Text = Px(a0(), a1())
End Sub
Private Function Px(aa%(), bb%()) As String
Dim a%, b%, c%, x%, y%, i%, m%
i = 0
For a = 1 To UBound(aa) - 2
For b = a + 1 To UBound(aa) - 1
For c = b + 1 To UBound(aa)
For x = 1 To UBound(bb) - 1
For y = x + 1 To UBound(bb)
i = i + 1 '行序列号
If i >= 1000 Then
m = 3 '行序列号后面的空格数,确保组合后的第一个数据对齐
ElseIf i >= 100 And i < 1000 Then
m = 4
ElseIf i >= 10 And i < 100 Then
m = 5
Else
m = 6
End If
Px = Px & i & Space(m) & Str(aa(a)) & Str(aa(b)) & _
Str(aa(c)) & Str(bb(x)) & Str(bb(y)) & vbCrLf
Next y, x, c, b, a
Label1.Caption = "一共有" & Str(i) & "种组合"
End Function 展开
Private Sub Command1_Click()
Dim a0() As Integer, a1() As Integer, x%, y$
y = InputBox("请输入a0数组元素个数", "输入数据", "5")
If Val(y) = 0 Or Val(y) = 1 Then Exit Sub
ReDim a0(1 To Val(y))
For x = 1 To UBound(a0)
y = InputBox("请输入a0数组第" & x & "个元素", "输入数据", "1")
If Val(y) = 0 Then Exit Sub
a0(x) = Val(y)
Next
y = InputBox("请输入a1数组元素个数", "输入数据", "4")
If Val(y) = 0 Or Val(y) = 1 Then Exit Sub
ReDim a1(1 To Val(y))
For x = 1 To UBound(a1)
y = InputBox("请输入a1数组第" & x & "个元素", "输入数据", "2")
If Val(y) = 0 Then Exit Sub
a1(x) = Val(y)
Next
Text1.Text = Px(a0(), a1())
End Sub
Private Function Px(aa%(), bb%()) As String
Dim a%, b%, c%, x%, y%, i%, m%
i = 0
For a = 1 To UBound(aa) - 2
For b = a + 1 To UBound(aa) - 1
For c = b + 1 To UBound(aa)
For x = 1 To UBound(bb) - 1
For y = x + 1 To UBound(bb)
i = i + 1 '行序列号
If i >= 1000 Then
m = 3 '行序列号后面的空格数,确保组合后的第一个数据对齐
ElseIf i >= 100 And i < 1000 Then
m = 4
ElseIf i >= 10 And i < 100 Then
m = 5
Else
m = 6
End If
Px = Px & i & Space(m) & Str(aa(a)) & Str(aa(b)) & _
Str(aa(c)) & Str(bb(x)) & Str(bb(y)) & vbCrLf
Next y, x, c, b, a
Label1.Caption = "一共有" & Str(i) & "种组合"
End Function 展开
2个回答
展开全部
以下程序实现:在文本框输入内容,按回车键(Enter键)后,文本框中的内容输出到列表框。
1)在窗体上布置一个TextBox控件和一个ListBox控件
2)代码
Option Explicit
Private Sub Form_Load()
' 窗体启动时,清空Text1和List1
Text1.Text = ""
List1.Clear
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
' 如果按下了回车键(回车键的Ascii码为13)
If KeyAscii = 13 Then
Dim s As String
' 取出Text1中输入的内容并滤除前后的空格
s = Trim(Text1.Text)
If s <> "" Then
' 如果Text1中输入的内容不为空,则添加到List1中
List1.AddItem s
' 添加后,清空Text1
Text1.Text = ""
End If
End If
End Sub
3)运行效果
窗体启动时
在Text1中输入,按回车后,输入的内容在List1中显示
展开全部
添加一个listbox,名称为list1
代码:
Private Sub Command1_Click()
Dim a0() As Integer, a1() As Integer, x%, y$
y = InputBox("请输入a0数组元素个数", "输入数据", "5")
If Val(y) = 0 Or Val(y) = 1 Then Exit Sub
ReDim a0(1 To Val(y))
For x = 1 To UBound(a0)
y = InputBox("请输入a0数组第" & x & "个元素", "输入数据", "1")
If Val(y) = 0 Then Exit Sub
a0(x) = Val(y)
Next
y = InputBox("请输入a1数组元素个数", "输入数据", "4")
If Val(y) = 0 Or Val(y) = 1 Then Exit Sub
ReDim a1(1 To Val(y))
For x = 1 To UBound(a1)
y = InputBox("请输入a1数组第" & x & "个元素", "输入数据", "2")
If Val(y) = 0 Then Exit Sub
a1(x) = Val(y)
Next
'Text1.Text = Px(a0(), a1())
Call Pxlist(a0(), a1(), List1)
End Sub
Private Sub Pxlist(aa%(), bb%(), l As ListBox)
Dim i&, a&, b&, c&, d&, x&, y&, m&, n&, z&, t&(4), s$(4)
For a = 1 To UBound(aa) - 2
For b = a + 1 To UBound(aa) - 1
For c = b + 1 To UBound(aa)
For x = 1 To UBound(bb) - 1
For y = x + 1 To UBound(bb)
i = i + 1 '行序列号
t(0) = aa(a): t(1) = aa(b): t(2) = aa(c): t(3) = bb(x): t(4) = bb(y)
For m = 0 To 4
For n = m + 1 To 4
If t(n) < t(m) Then z = t(m): t(m) = t(n): t(n) = z
Next
s(m) = Format(t(m), "00")
Next
l.AddItem Format(i, "@@@@ ") & Join(s)
Next y, x, c, b, a
Label1.Caption = "一共有" & Str(i) & "种组合"
End Sub
代码:
Private Sub Command1_Click()
Dim a0() As Integer, a1() As Integer, x%, y$
y = InputBox("请输入a0数组元素个数", "输入数据", "5")
If Val(y) = 0 Or Val(y) = 1 Then Exit Sub
ReDim a0(1 To Val(y))
For x = 1 To UBound(a0)
y = InputBox("请输入a0数组第" & x & "个元素", "输入数据", "1")
If Val(y) = 0 Then Exit Sub
a0(x) = Val(y)
Next
y = InputBox("请输入a1数组元素个数", "输入数据", "4")
If Val(y) = 0 Or Val(y) = 1 Then Exit Sub
ReDim a1(1 To Val(y))
For x = 1 To UBound(a1)
y = InputBox("请输入a1数组第" & x & "个元素", "输入数据", "2")
If Val(y) = 0 Then Exit Sub
a1(x) = Val(y)
Next
'Text1.Text = Px(a0(), a1())
Call Pxlist(a0(), a1(), List1)
End Sub
Private Sub Pxlist(aa%(), bb%(), l As ListBox)
Dim i&, a&, b&, c&, d&, x&, y&, m&, n&, z&, t&(4), s$(4)
For a = 1 To UBound(aa) - 2
For b = a + 1 To UBound(aa) - 1
For c = b + 1 To UBound(aa)
For x = 1 To UBound(bb) - 1
For y = x + 1 To UBound(bb)
i = i + 1 '行序列号
t(0) = aa(a): t(1) = aa(b): t(2) = aa(c): t(3) = bb(x): t(4) = bb(y)
For m = 0 To 4
For n = m + 1 To 4
If t(n) < t(m) Then z = t(m): t(m) = t(n): t(n) = z
Next
s(m) = Format(t(m), "00")
Next
l.AddItem Format(i, "@@@@ ") & Join(s)
Next y, x, c, b, a
Label1.Caption = "一共有" & Str(i) & "种组合"
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询