我有一个函数
Function transition(strId As String) As String
Dim cn As ADODB.Connection
Dim rsName As ADODB.Recordset
Dim strSQl As String
Dim strSingle As StringSet cn = New ADODB.Connection
cn.ConnectionString = "DSN=package;UID=;PWD=;"
cn.ConnectionTimeout = 30
cn.CursorLocation = adUseClient
cn.Open
strId = strId & ","
Set rsName = New ADODB.RecordsetWhile (strId <> "")
If Left(Trim(strId), 1) <> "," Then
strSingle = strSingle & Left(strId, 1)
strId = Right(strId, Len(strId) - 1)
Else
strSQl = "SELECT username FROM user WHERE userid = '" & strSingle & "'"
Set rsName = cn.Execute(strSQl)
transition = transition & rsName.Fields("username") & ","
strId = Right(strId, Len(strId) - 1)
strSingle = ""
End If
WendIf (transition <> "") Then
transition = Left(transition, Len(transition) - 1)
End If
End Function
编译报错说缺少数组,调试显示left有问题,不知道为什么?
我另外一个form中也用了left,但是就没有问题,而且结果正确,真奇怪!
Function transition(strId As String) As String
Dim cn As ADODB.Connection
Dim rsName As ADODB.Recordset
Dim strSQl As String
Dim strSingle As StringSet cn = New ADODB.Connection
cn.ConnectionString = "DSN=package;UID=;PWD=;"
cn.ConnectionTimeout = 30
cn.CursorLocation = adUseClient
cn.Open
strId = strId & ","
Set rsName = New ADODB.RecordsetWhile (strId <> "")
If Left(Trim(strId), 1) <> "," Then
strSingle = strSingle & Left(strId, 1)
strId = Right(strId, Len(strId) - 1)
Else
strSQl = "SELECT username FROM user WHERE userid = '" & strSingle & "'"
Set rsName = cn.Execute(strSQl)
transition = transition & rsName.Fields("username") & ","
strId = Right(strId, Len(strId) - 1)
strSingle = ""
End If
WendIf (transition <> "") Then
transition = Left(transition, Len(transition) - 1)
End If
End Function
编译报错说缺少数组,调试显示left有问题,不知道为什么?
我另外一个form中也用了left,但是就没有问题,而且结果正确,真奇怪!
Dim cn As ADODB.Connection
Dim rsName As ADODB.Recordset
Dim strSQl As String
Dim strSingle As String
Dim strTemp As StringSet cn = New ADODB.Connection
cn.ConnectionString = "DSN=package;UID=;PWD=;"
cn.ConnectionTimeout = 30
cn.CursorLocation = adUseClient
cn.Open
strId = strId & ","
Set rsName = New ADODB.RecordsetWhile (strId > "")
If Left(Trim(strId), 1) <> "," Then
strSingle = strSingle & Left(strId, 1)
strId = Right(strId, Len(strId) - 1)
Else
strSQl = "SELECT username FROM user WHERE userid = '" & strSingle & "'"
Set rsName = cn.Execute(strSQl)
strTemp = strTemp & rsName.Fields("username") & ","
strId = Right(strId, Len(strId) - 1)
strSingle = ""
End If
WendIf (strTemp > "") Then
strTemp = Left(strTemp, Len(strTemp) - 1)
End If
transition = strTemp
End Function在等号的右边引用函数名,会被认为是迭代调用函数,当然向你要参数了。
谁能告诉我是什么问题啊?