麻烦高手们再进来一下~我的程序有错了~
Dim info As String
Dim temp() As String
Dim a() As String
Dim b() As String
Dim i As Integer
Dim sname As String
Dim shome As String
sckServer(Index).GetData info, vbString
info = Left(info, Len(info) - 1)
temp = Split(info, "* ") '这时候temp= "黄永河*Y1101*茄汁香肠炒饭(5元)*腊味炒饭(5元) "
sname = temp(0) '记录名字
shome = temp(1) '记录宿舍
'下面是记录点餐订单和价钱
For i = 2 To UBound(temp) - 1
a(i) = Left(temp(i), InStr(temp(i), "饭 "))
b(i) = Mid(temp(i), Len(temp(i)) - 2, 1)
Next i
程序运行到a(i) = Left(temp(i), InStr(temp(i), "饭 "))时提示下标越界,请问怎么回事呢?
[解决办法]
应该这样
Dim info As String
Dim temp() As String
Dim a() As String
Dim b() As String
Dim i As Integer
Dim sname As String
Dim shome As String
sckServer(Index).GetData info, vbString
info = Left(info, Len(info) - 1)
temp = Split(info, "* ") '这时候temp= "黄永河*Y1101*茄汁香肠炒饭(5元)*腊味炒饭(5元) "
sname = temp(0) '记录名字
shome = temp(1) '记录宿舍
'下面是记录点餐订单和价钱
Redim a(UBound(temp)), b(UBound(temp))
For i = 2 To UBound(temp)
a(i) = Left(temp(i), InStr(temp(i), "饭 "))
b(i) = Mid(temp(i), Len(temp(i)) - 2, 1)
Next i