English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

我要計算班上五個同學的五科成績的平均,但程式一直無法執行結果,能請各位大大幫囉!謝謝!!
程式碼如下:

Dim ch, ch1, ch2, ch3, ch4, ag, ag1, ag2, ag3, ag4, pm, pm1, pm2, pm3, pm4, st, st1, st2, st3, st4, vb, vb1, vb2, vb3, vb4 As Integer
Dim Avg, Avg1, Avg2, Avg3, Avg4 As Single
ch = CInt(TextBox1.Text)
ag = CInt(TextBox2.Text)
pm = CInt(TextBox3.Text)
st = CInt(TextBox4.Text)
vb = CInt(TextBox5.Text)
Avg = TextBox26.Text
Avg = (ch + ag + pm + st + vb) / 5
ch1 = CInt(TextBox6.Text)
ag1 = CInt(TextBox7.Text)
pm1 = CInt(TextBox8.Text)
st1 = CInt(TextBox9.Text)
vb1 = CInt(TextBox10.Text)
Avg1 = TextBox27.Text
Avg1 = (ch1 + ag1 + pm1 + st1 + vb1) / 5
ch2 = CInt(TextBox11.Text)
ag2 = CInt(TextBox12.Text)
pm2 = CInt(TextBox13.Text)
st2 = CInt(TextBox14.Text)
vb2 = CInt(TextBox15.Text)
Avg2 = TextBox28.Text
Avg2 = (ch2 + ag2 + pm2 + st2 + vb2) / 5
ch3 = CInt(TextBox16.Text)
ag3 = CInt(TextBox17.Text)
pm3 = CInt(TextBox18.Text)
st3 = CInt(TextBox19.Text)
vb3 = CInt(TextBox20.Text)
Avg3 = TextBox29.Text
Avg3 = (ch3 + ag3 + pm3 + st3 + vb3) / 5
ch4 = CInt(TextBox21.Text)
ag4 = CInt(TextBox22.Text)
pm4 = CInt(TextBox23.Text)
st4 = CInt(TextBox24.Text)
vb4 = CInt(TextBox25.Text)
Avg4 = TextBox30.Text
Avg4 = (ch4 + ag4 + pm4 + st4 + vb4) / 5

2006-12-02 17:24:04 · 4 個解答 · 發問者 小如 1 in 電腦與網際網路 程式設計

CInt就是將參數的值轉換成整數
我把Cint改成val,但還是無法計算出答案
Avg = TextBox26.Text一直還是會出現偵錯

2006-12-03 11:49:40 · update #1

感謝各位大大的回答,我已經知道錯誤在那裡了,謝謝囉!

2006-12-04 11:29:27 · update #2

4 個解答

你說 Avg = TextBox26.Text一直出現錯誤
請問你 TextBox26.Text是打什麼東西 ,如果是數值應該不會錯
如果不是數值就會出現 型態不符
改成 Avg = val(TextBox26.Text) 這樣就不會出現型態不符

有問題再提出吧!!!

2006-12-03 20:05:31 · answer #1 · answered by ANDY 2 · 0 0

你犯的錯誤可能有下
Dim ch as integer, ch2 as integer,ch3 as integer.. 這樣才會每個都是int
名稱錯誤,vb拉出來預設是text1.text除非你把text1的name屬性改掉
要指派avg的時後先把數字存入avg在丟進textbox內
Avg = csng ((ch + ag + pm + st + vb) / 5)
text99.text=avg

2006-12-04 11:39:42 補充:
做個小修正以防止出來的平均數是整數Avg = csng (ch + ag + pm + st + vb) /5text99.text=avg

2006-12-03 18:49:56 · answer #2 · answered by 鉦傑 3 · 0 0

我是不知道你打這個程式是什麼樣的
不過依照你的宣告肯定不是給外人看的(因為我看不懂)

可以把你整個程式貼出來嗎?

2006-12-02 17:56:32 · answer #3 · answered by ? 2 · 0 0

CInt是什麼東東阿

應該是val

val(text1.text)
你在試試

成積最好用sin...這個...變數

2006-12-02 17:56:19 · answer #4 · answered by 偉⊙ 7 · 0 0

fedest.com, questions and answers