哦,我的上帝,我討厭這件事,我嘗試了數百萬種方法,但找不到工作。讓我解釋一下:VB - 索引超出範圍?
我正在測試每一行並檢查第一個單詞是「複製」好嗎?如果所有這些條件都已滿滿,那麼「<」和「>」之間的文本需要滿足以下條件:「我想要查看下一個單詞是否爲」1「,第三個是」<「,最後是」>「存儲在變量「copy1」中(即使它們之間存在多於1個單詞)。
什麼我的代碼是:
For i = 0 To lstCode.Items.Count - 1
Dim str As String = lstCode.Items.Item(i)
Dim strA() As String = Split(str)
Dim copy1 as string
Dim copy2 as string
Select Case strA(0)
Case copy
If strA(1) = "1" And strA(2) = "<" And strA(strA.Count - 1) = ">" Then
copy1 = ""
For lr As Integer = 3 To strA.Count - 2
copy1 &= (strA(lr) & " ")
Next
End if
End select
,當我調試它,我得到的錯誤:索引數組...的邊界之外沒有任何人有什麼想法?
有一些重要的事情我忘了補充,這是整個代碼:
Case "copy"
If strA(1) = "1" And strA(2) = "<" And strA(strA.Count - 1) = ">" Then
copy1 = ""
For lr As Integer = 3 To strA.Count - 2
copy1 &= (strA(lr) & " ")
Next
ElseIf strA(1) = "2" And strA(2) = "<" And strA(strA.Count - 1) = ">" Then
copy2 = ""
For lrs As Integer = 3 To strA.Count - 2
copy2 &= (strA(lrs) & " ")
Next
ElseIf strA(1) = "run" Then
Try
IO.File.Copy(copy1, copy2)
Catch ex As IO.IOException
End Try
End If
End Select
所以,一切就像一個魅力:複製1 < C:\ csb.log>,複製2 < c:\ blabla.txt>但當「複製運行」語句進入時,它給我錯誤...
我忘了說我正在使用Visual Basic 2010.對不起。 – Bpk7
你在哪個行中得到了那個錯誤? – har07