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

发布时间:2021-02-25 12:12:07

VB编程:单击mand1,则随机产生10个0~100之间的数值,将之保存到一维数组中a中,同时显示在text1中.单击mand2,则弹出对话框,接受用户输入的任意一个数,并在一维数组中查找该数,若查找失败,则在text2中显示“不存在于数组中”,否则给出该数组中的位置.

网友回答

dim a(9) as integer
private sub mand1_click()
dim i as integer
randomize
for i=0 to 9
a(i)=int(rnd*101)
text1.text=text1.text & a(i) & ,
next iend sub
private sub mand2_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 ifnextif c=false then text2.text=不存在于数组中 else text2.text=在数组中的位置= & i+1
end sub
以上问题属网友观点,不代表本站立场,仅供参考!