用VB寫 計算十個整數之平均值
1.使用者必須逐一輸入10個整
要用WHILE....WEND
我有試解過 但答案是錯的 給你們參考
private Sub Command1_Click()
Dim a As Integer
Dim sum As Integer
Dim num As Integer
a = Text1
sum = 0
num = 0
While num <= 10
sum = sum + a
num = num + 1
Text1 = \"\"
Wend
Label1 = sum / 10
End Sub
2006-07-22 20:20:32 · 1 個解答 · 發問者 華仔 2 in 電腦與網際網路 ➔ 程式設計
你做的算是算出來了,但是為什麼在另外一個視窗輸入數字呢,不太懂,可以解釋一下嗎
2006-07-23 10:48:41 · update #1
Private Sub Command1_Click() Dim a As Integer Dim sum As Integer Dim num As Integer While num < 10 a = Int(Val(InputBox("輸入整數"))) sum = sum + a num = num + 1 Wend Label1 = sum / 10End Sub
2006-07-23 15:24:33 補充:
因為這是比較常用的作法,InputBox會讓程式停下來等使用者輸入完畢後才繼續往下跑,利用InputBox函數剛剛好能符合此題的需求!
2006-07-22 20:51:37 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋