VB编程:单击command1,则随机产生10个0~100之间的数值,将之保存到一维数组中a中,同时显示在text1中。

单击command2,则弹出对话框,接受用户输入的任意一个数,并在一维数组中查找该数,若查找失败,则在text2中显示“不存在于数组中”,否则给出该数组中的位置。

dim a(9) as integer

private sub command1_click()
dim i as integer
randomize
for i=0 to 9
a(i)=int(rnd*101)
text1.text=text1.text & a(i) & ","
next i
end sub

private sub command2_click()
dim b as integer,i as integer,c as boolean
b=val(inputbox("请输入一个数字"))
c=false
for i=0 to 9
if b=a(i) then
c=true
exit for
end if
next
if c=false then text2.text="不存在于数组中" else text2.text="在数组中的位置=" & i+1
end sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-05-07
Private Sub command1_click()
Dim a(10) As Integer
Dim temp As Long
For i = 1 To 10
a(i) = Int(Rnd * 100 + 0.5)
Next i
Text1.Text = a(1) & Space(2) & a(2) & Space(2) & a(3) & Space(2) & a(4) & Space(2) & a(5) & Space(2) & a(6) & Space(2) & a(7) & Space(2) & a(8) & Space(2) & a(9) & Space(2) & a(10)
End Sub
Private Sub command2_click()
Dim a As Variant
Dim much As Long, temp As Long
much = Val(InputBox("请输入一个整数"))
a = Split(Text1.Text, " ")

For i = 0 To 8
For j = i + 1 To 9
If a(i) > a(j) Then
temp = a(i)
a(i) = a(j)
a(j) = temp
End If
Next j
Next i
low = 0: Top = 9
f = 0
Do
t = Int((Top + low) / 2)
If much = a(t) Then
f = 1
Else
If much > a(t) Then
low = t + 1
Else
Top = t - 1
End If
End If
Loop While (low < Top) And (f = 0)
If f = 1 Then
Text2.Text = a(t)
Else
Text2.Text = "该数不存在于数组中"
End If
End Sub

...一个VB程序,点击command1时,随机产生10个0到100的随机整数,并将其显...
Private Sub command1_click()Dim a(10) As Integer Dim temp As Long For i = 1 To 10 a(i) = Int(Rnd * 100 + 0.5)Next i Text1.Text = a(1) & Space(2) & a(2) & Space(2) & a(3) & Space(2) & a(4) & Space(2) & a(5) & Space(2) & a(6) & Sp...

用VB编程:随机产生10个0~100之间的随机整数,存放在一个数组中,然后求个...
Print "平均值=" & x \/ 10 For i = 0 To 9 If a(i) > (x \/ 10) Then j = j + 1: y = y & CStr(a(i)) & " "Next i Print "大于平均值的元素个数=" & j Print "大于平均值的元素:" & y Me.Refresh End Sub ...

vb单击“数列生成”按钮,自动生成10个10~90之间的随机整数,存于...
Dim a(1 To 10) As IntegerPrivate Sub Command1_Click() List1.Clear Randomize (Timer) For i = 1 To 10 a(i) = Int(Rnd(i) * 81 + 10) List1.AddItem a(i) Next iEnd SubPrivate Sub Command2_Click() List2.Clear For i = 1 To 9 For j = i + 1 ...

vb随机产生10个整数,范围在[0,100]之间,放在数组A中,按递增序列排序
Private Sub Command1_Click()Dim i As Integer, j As Integer, exchange As Integer, a(9) As Integer For i = 0 To 9 Randomize a(i) = Rnd * (101)Next i For i = 1 To 9 For j = 0 To 9 - i If a(j) > a(j + 1) Then exchange = a(j)a(j) = a(j + 1)...

...程序,利用随机函数产生并显示10 个1~100 之间的随机整数并找出这个...
Private Sub Command1_Click() Dim a(10) As Integer Randomize Max = 1 For i = 1 To 10 a(i) = 1 + Int(Rnd * 100) Print a(i); If a(i) > a(Max) Then Max = i Next i Print Print "a("; Max; ")="; a(Max)End Sub ...

计算机VB中,利用随机函数产生10个10-100的随机数,并将其赋值给数组a...
Private Sub Command1_Click() Dim a(10) As Integer Randomize For i = 1 To 10 a(i) = Int(Rnd() * 91) + 10 Print a(i); s = s + a(i) Next i Print Print "平均值="; s \/ 10End Sub

VB中,随机产生10个0~100之间的随机数,按从小到大的顺序排列怎么做...
1 - 100 之间选 20 个随机数Trec = 10 End Sub Private Sub Command1_Click() S = GetRnd(1, 100, Trec) Me.ClsFor i = 0 To Trec - 1 Print S(i) Next i End Sub Private Sub Command2_Click()'*** 由小排到大(冒泡排序法)Me.Cls For i = 0 To Trec - 1 k = i For...

vb编程:随机产生10个1–100之间的整数,并按从小到大顺序输出,谁能帮我...
Private Sub Command1_Click()Dim a(10), i, j As Integer For i = 0 To 9 a(i) = Int(Rnd * 100) + 1 Print a(i);Next For i = 0 To 8 For j = i To 9 If a(i) > a(j) Then t = a(i)a(i) = a(j)a(j) = t End If Next Next Print For i = 0 To...

用VB写代码产生10个100-200的随机数,保存在数组中,从小到大排序,输出...
To UBound(a) a(i) = Int(Rnd * 101) + 100 Next For i = 0 To UBound(a) - 1 For j = 0 To UBound(a) - i - 1 If a(j) > a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = t End If Next j, i Me.Cls Fo...

用vb设计一个程序:从0到100中随机抽取10个数,保存到数组中,查找出最大...
Sub Form_Load()Me.Caption = "李四"Command1.Caption = "生成"Command2.Caption = "查找"Me.AutoRedraw = TrueDim j As Long, t As StringFor j = 1 To 10Randomizesz(j - 1) = Rnd() * 99 + 1t = t & Space(1) & sz(j - 1)If j Mod 10 = 0 ThenPrint tt = ""...

相似回答