vb split 问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 11:12:05
Dim w_s As String, w_d As String, sp As String
Function cc()
w_s = "a,b,c,d,e,f,g,h"
sp = Split(w_s, "," - 1)
For i = LBound(sp) To UBound(sp)
MsgBox sp(i)
Next
End Function

Private Sub Command1_Click()
Call cc
End Sub

*****************************************************

报错:缺少数组 ?

你的sp根本就没有定义为数组啊,但又在当成数组用。
另外 Split(w_s, "," - 1) 这句,你也少打了一个逗号。
按我的修改:

Dim w_s As String, w_d As String, sp() As String
Function cc()
Dim i As Integer
w_s = "a,b,c,d,e,f,g,h"
sp = Split(w_s, ",", -1)
For i = LBound(sp) To UBound(sp)
MsgBox sp(i)
Next
End Function

Private Sub Command1_Click()
Call cc
End Sub