1樓:匿名使用者
此方法是用隨機數產生20個不重複的數,顯示20個數,再挑出奇數,再排列,再顯示。數字之間用空格隔開。
private sub command1_click()text1 = "": text2 = ""
dim a(1 to 20), b(1 to 20) as integer
dim i, i1, i2, j, j1, j2, j3, j4, t as integer
j1 = 1
for i = 1 to 20 '以下產生不重複隨機數到a陣列a(i) = int(rnd() * 100 + 1)for i1 = 1 to i - 1
if a(i) = a(i1) then
i1 = i1 - 1
i = i - 1
end if
next i1, i
for i2 = 1 to 20 '顯示這20個隨機數text1 = text1 & a(i2) & " "
next
for j = 1 to 20 '挑出奇數到b陣列if a(j) mod 2 <> 0 thenb(j1) = a(j)
j1 = j1 + 1
end if
next
for j2 = 1 to j1 - 1 '排列奇數for j3 = 1 to j1 - 1
if b(j2) < b(j3) thent = b(j2)
b(j2) = b(j3)
b(j3) = t
end if
next j3, j2
for j4 = 1 to j1 - 1 '顯示奇數text2 = text2 & b(j4) & " "
next
end sub
2樓:匿名使用者
如果文字框1中的數字都是用逗號隔開的話:
dim a
dim b
a=split(text1.text,",")dim i%,j$,k%,m%,n%
for i = 0 to 19
if a(i) mod 2 =0 thenj=j & a(i) & ","
end if
next
b=split(j,",")
for k = 0 to 18
for m=k+1 to 19
if b(k)>b(m) then
n=b(k)
b(k)=b(m)
b(m)=n
end if
next
next
for i =0 to 19
j=j & b(i) & " "
next
text2.text=b
vb程式設計問題
private sub command1 click dim i,j as integer,s as double,n as double for i 1 to 100 n 1 for j 1 to i n n j next j s s n next i print 1 2 100 send sub...
VB程式設計問題請教
if then語句有行語句和塊語句.你這樣寫,第2個if a1 375 then a2 0.571 是行語句 你看給你整理下.private sub command5 click if a1 0 and a1 1000 then if a1 375 then a2 0.571 elseif a1 4...
vb6 0程式設計問題,求解答
w.paintpicture pic.picture,i,j,pic.scalewidth,pic.scaleheight pic.scalewidth pic.scaleheight 對嗎?nexy j next拼寫錯誤 for j 0 to w.height step pic.scaleheig...