求做一个VB的小程序,求代码,急
要求:从200~300中随机抽取10个数字,输出到文本框1中,通过按键单击事件(command的click),选出其中最大的数字及其序号(即是之前生成10个数字中的第几个...
要求:从200~300中随机抽取10个数字,输出到文本框1中,通过按键单击事件(command的click),选出其中最大的数字及其序号(即是之前生成10个数字中的第几个)输出到文本框2中。
要求就是这样了,先谢过了~ 展开
要求就是这样了,先谢过了~ 展开
3个回答
展开全部
Private Sub Command1_Click()
Dim a(1 To 10) As Integer, Max As Integer
Randomize
Text1.Text = ""
For i = 1 To 10
a(i) = Int(Rnd() * 101) + 200 & " "
Text1.Text = Text1.Text & a(i) & " "
Next
Max = 1
For i = 2 To 10
If a(i) > a(Max) Then
Max = i
End If
Next
Text2.Text = "最大的数字:" & a(Max) & " 序号:" & Max
End Sub
'以上
Dim a(1 To 10) As Integer, Max As Integer
Randomize
Text1.Text = ""
For i = 1 To 10
a(i) = Int(Rnd() * 101) + 200 & " "
Text1.Text = Text1.Text & a(i) & " "
Next
Max = 1
For i = 2 To 10
If a(i) > a(Max) Then
Max = i
End If
Next
Text2.Text = "最大的数字:" & a(Max) & " 序号:" & Max
End Sub
'以上
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
文本框名称分别为txt1、txt2
按钮名称为cmd1
假设文本框中的10个数以逗号隔开。
Option Explicit
Private Sub cmd1_click()
Dim i As Integer, s As String
Dim max As Integer, ind As Integer
s = txt1.Text
max = Val(Left(s, 3))
ind = 1
For i = 2 To 10
s = Mid(s, InStr(s, ",") + 1)
If (max < Val(Left(s, 3))) Then
max = Val(Left(s, 3))
ind = i
End If
Next
txt2.Text = "第" & ind & "数最大,其值为" & max & "。"
End Sub
Private Sub Form_Load()
Dim i As Integer
Randomize
txt1.Text = Int(200 + Rnd * 201)
For i = 1 To 10
txt1.Text = txt1.Text & "," & Int(100 + Rnd * 201)
Next
End Sub
按钮名称为cmd1
假设文本框中的10个数以逗号隔开。
Option Explicit
Private Sub cmd1_click()
Dim i As Integer, s As String
Dim max As Integer, ind As Integer
s = txt1.Text
max = Val(Left(s, 3))
ind = 1
For i = 2 To 10
s = Mid(s, InStr(s, ",") + 1)
If (max < Val(Left(s, 3))) Then
max = Val(Left(s, 3))
ind = i
End If
Next
txt2.Text = "第" & ind & "数最大,其值为" & max & "。"
End Sub
Private Sub Form_Load()
Dim i As Integer
Randomize
txt1.Text = Int(200 + Rnd * 201)
For i = 1 To 10
txt1.Text = txt1.Text & "," & Int(100 + Rnd * 201)
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a(10) As Integer, i As Integer, j As Integer, max As Integer, xishu As Integer
max = 0
Text1.Text = ""
xishu = 0
For i = 0 To 9
a(i) = Rnd * 100 + 200
Text1.Text = Text1.Text & a(i) & " "
If max < a(i) Then
max = a(i)
xishu = i
End If
Next i
Text2.Text = xishu
End Sub
Dim a(10) As Integer, i As Integer, j As Integer, max As Integer, xishu As Integer
max = 0
Text1.Text = ""
xishu = 0
For i = 0 To 9
a(i) = Rnd * 100 + 200
Text1.Text = Text1.Text & a(i) & " "
If max < a(i) Then
max = a(i)
xishu = i
End If
Next i
Text2.Text = xishu
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询