VB的inputbox怎么实现连续输入10个整数作为数组进行排序操作? VB用inputbox输入10个整数,用冒泡排序法从小到大排...
VB\u7528inputbox\u8fde\u7eed\u8f93\u516510\u4e2a\u6570 \u7136\u540e\u5206\u522b\u8fdb\u884c\u5347\u964d\u5e8f\u6392\u5217 \u7136\u540e\u7ed3\u679c\u663e\u793a\u5728TEXT\u4e0aPrivate Sub Command1_Click()
Dim a(1 To 10) As Integer
Dim n As Integer
Dim i As Integer
Dim j As Integer
For i = 1 To 10
a(i) = Val(InputBox("\u8f93\u5165\u7b2c" & i & "\u4e2a\u6570"))
Next i
For i = 1 To 10
For j = 1 To 10
If a(i) < a(j) Then
n = a(i)
a(i) = a(j)
a(j) = n
End If
Next j
Next i
Print "\u5347\u5e8f"
Text1.Text = "\u5347\u5e8f:"
For i = 1 To 10
Print a(i);
Text1.Text = Text1.Text & a(i) & " "
Next
Print
Print "\u964d\u5e8f"
Text1.Text = Text1.Text & "\u964d\u5e8f:"
For i = 10 To 1 Step -1
Print a(i);
Text1.Text = Text1.Text & a(i) & " "
Next i
Print
End Sub
'\u6dfb\u52a0\u4e00\u4e2a\u6309\u94ae\u7136\u540e\u5355\u51fb
Private Sub Command1_Click()
Dim a(10) As Integer
For i = 1 To 10
a(i) = InputBox("\u8bf7\u8f93\u5165a(" & i & ")\uff1a")
Print a(i);
Next i
Print
For i = 1 To 9
For j = 1 To 10 - i
If a(j) > a(j + 1) Then
t = a(j)
a(j) = a(j + 1)
a(j + 1) = t
End If
Next j
Next i
Print "\u6392\u5e8f\u4ee5\u540e\uff1a"
For i = 1 To 10
Print a(i);
Next i
Print
End Sub
1、打开VB6.0开发软件,新建一个标准exe工程;
2、在设计界面上添加两个Label控件、两个个Text控件和一个Command控件,各控件属性如下图所示;
3、双击Command1控件,进入代码编辑界面,输入如下代码:
Private Sub Command1_Click()
Dim a(10) As Integer
Text1.Text = ""
Text2.Text = ""
For i = 1 To 10
a(i) = InputBox("请输入第" & i & "个数字")
Next i
For i = 1 To 10
Text1.Text = Text1.Text & a(i) & " "
Next i
For i = 1 To 10
For j = 1 To 10 - i
If a(j) > a(j + 1) Then
temp = a(j + 1)
a(j + 1) = a(j)
a(j) = temp
End If
Next j
Next i
For i = 1 To 10
Text2.Text = Text2.Text & a(i) & " "
Next i
End Sub
4、运行工程,单击Command按钮,可以看到通过Inputbox输入的原数组和排序后的数组。
帮你写了个简单的程序,应该能看懂吧。如下所示:
Dim a%(1 To 10)
Private Sub Command1_Click()
For i = 1 To 10
a(i) = InputBox("请输入整数")
Print a(i);
Next i
End Sub
Private Sub Command2_Click()
'用选择排序法排序
For i = 1 To 9
k = i
For j = i + 1 To 10
If a(j) < a(k) Then k = j
Next j
temp = a(k)
a(k) = a(i)
a(i) = temp
Next i
Print "十个数从小到大排列顺序为:"
For i = 1 To 10
Print a(i);
Next i
End Sub
扩展阅读:vb中integer ... vba listbox实例 ... vb listbox用法 ... msgbox在vb中的用法 ... vb清空picturebox ... 手机vbs编写 ... vb msgbox用法实例 ... bbox教学 ... vb的五个特点 ...