我有一个函数
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,但是就没有问题,而且结果正确,真奇怪!

解决方案 »

  1.   

    我也有过这种情况,你保存后重新开一次看看有没有什么问题。实在不行,我一般就是用mid来代替它做呵呵
      

  2.   

    改为while (trim(strid)<>"" )试一下
      

  3.   

    Function transition(strId As String) As String
    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在等号的右边引用函数名,会被认为是迭代调用函数,当然向你要参数了。
      

  4.   

    of123()按照你说的改了,还是不行。最后还是把所有的left,right都改用了mid才解决了。
    谁能告诉我是什么问题啊?