嘿傢伙我在閱讀我的程序的config.cfg文件時遇到問題。我可以讀取該文件的23.字符,但我無法讀取24. char(文件中的最後一個字符)。VB 2008 - 索引超出了陣列的範圍
這是代碼:
Dim CFGReader2 As System.IO.StreamReader
CFGReader2 = _
My.Computer.FileSystem.OpenTextFileReader(CurDir() & "\Config.cfg")
Dim Server(2) As String
Server(0) = CFGReader2.ReadToEnd.Chars(23)//This part works
If Server(0) = 0 Then
Server(1) = CFGReader2.ReadToEnd.Chars(24)//This part results in "Index was outside the bounds of the array".
ElseIf Server(0) = 1 Then
Server(2) = CFGReader2.ReadToEnd.Chars(24)//This part results in "Index was outside the bounds of the array".
Server(1) = 10 + Server(2)
ElseIf Server(0) = 2 Then
Server(2) = CFGReader2.ReadToEnd.Chars(24)//This part results in "Index was outside the bounds of the array".
Server(1) = 20 + Server(2)
ElseIf Server(0) = 3 Then
Server(2) = CFGReader2.ReadToEnd.Chars(24)//This part results in "Index was outside the bounds of the array".
Server(1) = 30 + Server(2)
End If
這是文件:
語言= 2
服務器= 11
感謝您的回答!
Frosty
你能修復代碼,所以它會工作,因爲我認爲我不明白它? 謝謝。 – Jan 2010-04-30 10:15:24
那裏我沒有糾正你的代碼,但已經告訴你爲什麼它不是正確的。 – ChrisBD 2010-04-30 10:46:26
感謝您的答案,但它似乎是錯誤的。當我測試什麼是23. char它說它是1(在txt文件中,我將「Server = 11」更改爲「Server = 10」)。但是當我聽你的時候,22.char是SPACE。所以錯誤是「從字符串轉換」到「雙精度型」無效。「但是,當我想要獲得24個字符時,它仍然是同樣的舊錯誤。 幫助並感謝您的回答。 哦,還有一件事:如果我在這兩種情況下使用23. char(之前和之後),第一個是好的,但第二個給我錯誤。 – Jan 2010-04-30 11:04:55