VB的inputbox怎么实现连续输入10个整数作为数组进行排序操作?
不好意思,关键问题是怎样让输入非数字字符时弹出警告框并重新输入,我的程序可以做到,但是是继续输入而不是重新输入。要求必须输入10个数。...
不好意思,关键问题是怎样让输入非数字字符时弹出警告框并重新输入,我的程序可以做到,但是是继续输入而不是重新输入。要求必须输入10个数。
展开
展开全部
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
Print "十个数从小到大排列顺序为:"
For i = 1 To 10
Print a(i);
Next i
End Sub
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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询