VB程式編寫 某陣列有元素,元素的值由鍵盤輸入,要求將前元素與後元素對換。高分懸賞

時間 2021-07-21 03:33:35

1樓:匿名使用者

private sub command1_click()dim str as string

dim arr(1 to 20) as stringfor i = 20 to 1 step -1arr(i) = inputbox("請輸入第 " & (21 - i) & "個數")

str = str & arr(i) & " "

next

print "交換前: " & vbcrlf & strprint "交換後: "

for i = 1 to ubound(arr)print arr(i) & " ";

next

end sub

2樓:匿名使用者

private sub command1_click()dim a(1 to 20)

for i = 1 to 20

a(i) = val(inputbox("請你輸入第" & i & "個數"))

next i

print "交換前的數為"

for i = 1 to 20

print a(i);

if i mod 10 = 0 then printnext i

for i = 1 to 10

b = a(i): a(i) = a(21 - i): a(21 - i) = b

next i

print "交換後的數為"

for i = 1 to 20

print a(i);

if i mod 10 = 0 then printnext i

end sub

private sub form_load()me.autoredraw = true

end sub

3樓:匿名使用者

dyeb @@@cfsx 19d si

4樓:古龍珈藍玉

vb程式設計的輸入編寫的時候要注意寫作速度,元素,v的輸入

vb程式設計:某陣列中有10個元素,元素的值由鍵盤輸入,要求將前5個元素與後5個元素對換,

5樓:良陣

dim a() as integer ’原來的陣列dim b() as integer '換後的陣列dim i as integer

for i=0 to 4

b(i)=a(9-i)

b(9-i)=a(i)

next i

你要怎麼樣輸入輸出資料?是一個一個輸,輸10次還是一個textbox中輸入10個數中間用空格隔開

輸出,是在另一個textbox中顯示還是msgbox彈出來顯示

6樓:匿名使用者

private sub command1_click()dim a(1 to 10) as integerdim i as integer, tmp as integerfor i = 1 to 10

a(i) = inputbox("input number")print a(i);

next

print

for i = 6 to 10

tmp = a(i - 5)

a(i - 5) = a(i)

a(i) = tmp

next

for i = 1 to 10

print a(i);

next

7樓:匿名使用者

直接伸手啊,把你會的**拿出來,我幫你發言

(1/2)用vb程式程式設計:從鍵盤上輸入10個整數,並放入一個一維陣列中,然後將其前5個元素與後5個元素對換... 40

8樓:司寇忻

private sub command1_click()

dim tmp as string, tmp1 as string, a() as string

me.cls

tmp = text1.text

if not isnumeric(tmp) then goto outerr

a = split(tmp, ",")

if ubound(a) <> 9 then msgbox "請輸入十個整數!", vbinformation, "提示": exit sub

for i = 0 to 4

tmp1 = a(i)

a(i) = a(9 - i)

a(9 - i) = tmp1

next i

for i = 0 to 9

if int(val(a(i))) = val(a(i)) then

me.print a(i) & ",";

else

me.print a(i) & "(不是整數)";

end if

next i

exit sub

outerr:

a = split(tmp, ",")

for i = 0 to ubound(a)

if not isnumeric(a(i)) then me.print vbcrlf & a(i) & "不是整數"

next i

end sub

private sub text1_change()

dim a() as string

a = split(text1.text, ",")

if a(ubound(a)) <> "" then label1.caption = "共輸入:" & ubound(a) + 1 & "個數"

end sub

9樓:櫻雪殤

option base 1

private sub form_click()dim a%(10)

for i = 1 to 10

a(i) = inputbox("輸入第" & i & "個元素值:")

print a(i);

next i

print

for i = 1 to 5

temp = a(i): a(i) = a(11 - i): a(11 - i) = temp

next i

for i = 1 to 10

print a(i);

next i

end sub

用vb編寫求元素的一維陣列A,使用INPUTBOX函式賦值,輸出最小元素的值及其下標

尤在尤存 一樓有問題.dim a 19 as double for i 0 to 19 a i inputbox 請輸入一個數 next dim min1 as double 記錄最小值dim min2 as integer 記錄下標min1 a 0 min2 0 要賦初值for i 1 to 19...

VB給陣列 賦值,急急急,VB中給陣列元素賦初值

為定義陣列大小.需要先定義data2 list陣列大小 redim data2 list n n為指定值.vb中給陣列元素賦初值 有問題請追問,滿意請採納,新年快樂!加油!1 vb6定義陣列時不需要人為初始化陣列,它會自動把數值型陣列的每個元素初始化為0,把字串陣列的每個元素初始化為空串。2 如果你...

VB語言定義大小為元素的整型陣列

司馬刀劍 private sub command1 click dim a n as integera array 999,15,28,37,45,58,61,75,85,90,92 print 原有的陣列元素是 for i 1 to ubound a print a i next i print ...