新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim bArr() As Byte, bArr2() As Byte
Dim strA As String, strB As String
ReDim bArr2(0)
strA = "MaNongKu.com"
bArr = strA
'Debug.Print "bArr=" & bArr '这样会出错
Debug.Print "bArr:"
Debug.Print bArr
strB = bArr
Debug.Print "strB=" & strB
bArr2 = strA
Debug.Print "bArr2:"
Debug.Print bArr2(0) & " " & bArr2(1) & " " & bArr2(2) & " " & bArr2(3) & " " & bArr2(4) & " " & bArr2(23)
End Sub
运行结果:
bArr:
MaNongKu.com
strB=MaNongKu.com
bArr2:
77 0 97 0 78 0
当& bArr2(24)的时候,就会显示下标出错,看来VB6是默认先给到0-23一共24个下标,而不是只给ReDim定义的0个。就算这个0改成60,仍然到24就出错。