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

請問下面的程式碼哪邊錯了 為什麼啟動後都會顯示陣列索引超出範圍

Private Sub Command1_Click()
w = 0
T1 = Val(T1)
a = Split(T1, " ")
b = Val(a(0)): c = Val(a(1))
If 0 < b < 10000 And 0 < c < 10000 Then
For i = b To c
If i > 1 Then
If i Mod 2 = 1 Then
i = 3 * i + 1
t = t + 1
Else
i = i / 2
t = t + 1
End If
End If
If t > w Then
w = t
End If
Next i
Else
L1 = "輸入錯誤"
End If
L2 = a(0) & " " & a(1) & w
End Sub

2006-09-29 13:49:29 · 1 個解答 · 發問者 小心我的獵頭腳 1 in 電腦與網際網路 程式設計

1 個解答

T1 = Val(T1)1.T1 你並沒有給它任何值2.T1 = Val(T1) , Val函數是把任意值轉成數字(Double),因此T1=0,故T1 = Val(T1) 這行一定要拿掉!a = Split(T1, " ") 你用" "要去分割T1給a,此時T1=0當然就分割不出來了,故a(0),a(1)一定會引發陣列索引超出範圍的錯誤.

2006-09-29 15:42:32 · answer #1 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers