Q
指數是數組的範圍
2
A
回答
12
這意味着,你RichTextBox1
中有沒有線。替換與:
Dim placename As String
If RichTextBox1.Lines.Count() > 0 Then
placename=RichTextBox1.Lines(0)
Else
placename = String.Empty
End if
更多信息:
想象數組作爲街道和陣列中的每個元素是一個房子。如果街上有30間房屋,我想找20號房屋,那麼我從開始(1)開始,直到達到20爲止。對於一個數組,0是從哪裏開始而不是1,所以一個數組有30個元素,包含索引0-29。現在回到街頭比喻。想象一下,我走上街頭,要求房子號碼31.這棟房子不存在,因爲只有30間房屋。這實際上是該計劃告訴你的。它是說'陣列中沒有足夠的元素讓我找到你要求的元素'。所以你問了行數組中的元素0,有效地說'給我第一行'。現在,如果文本框中有0行,那麼第一行不存在,您將得到此錯誤。
0
指數數組
該錯誤消息的邊界之外通常意味着你已經呼籲在那個爲空,或者有什麼也沒有的位置數組中的對象。它發生在如下的情況下。
myArray = [0,1,2,3];
trace(myArray[6]);
由於在索引6處數組中沒有任何內容,所以它在邊界之外。如果在調用時該陣列爲空,它將給出索引爲0的對象的錯誤。
我無法通過您發佈的代碼量來告訴任何更多。嘗試檢查以確保在調用該行之前已經填充了該數組。
0
也許你的SQL讀取器沒有得到任何與你給出的索引相關的行。對我來說就是這樣。我收到了不在數據庫中的列。
如下你可以改變你的代碼:
Dim placename As String
If RichTextBox1.Lines.Count > 0 Then placename = RichTextBox1.Lines(0)
0
子ambil_kode_barang() 昏暗contoh的String = TRIM(tnama.Text)
Dim myc, myc2, myc3, myc4 As Char
Dim x, x2, x3 As Byte
Dim xdaerah, xdaerah2, xdaerah3, hasil As String
Dim s As Integer
myc = contoh.Chars(0)'zero this error can you help me.?
s = Len(contoh) - Len(Replace(contoh, " ", ""))
x = InStr(contoh, " ")
xdaerah = Microsoft.VisualBasic.Mid(tnama.Text, x + 1, Len(tnama.Text) - x)
myc2 = xdaerah.Chars(0)
x2 = InStr(Trim(xdaerah), " ")
xdaerah2 = Microsoft.VisualBasic.Mid(xdaerah, x2 + 1, Len(xdaerah) - x2)
myc3 = xdaerah2.Chars(0)
x3 = InStr(Trim(xdaerah2), " ")
xdaerah3 = Microsoft.VisualBasic.Mid(xdaerah2, x3 + 1, Len(xdaerah2) - x3)
myc4 = xdaerah3.Chars(0)
If s = 0 Then
hasil = Strings.Left(contoh, 2)
ElseIf s = 1 Then
hasil = myc + myc2
ElseIf s >= 2 Then
hasil = myc + myc2
Else
hasil = myc + myc2
End If
ambil_kode = Trim(hasil.ToUpper)
End Sub
你應該多增加一些細節,而不僅僅是粘貼一些代碼。您的解決方案如何以及爲何解決問題? 並請格式化您的代碼。 – hering 2017-08-28 13:51:28