我先在模块中定义了个函数
Public Function method00(max_up As Integer, carname2, carname3 As String)
..............
end function
  在一个窗口中引用这个参数
    Dim max2 As Integer
    Dim sma, mid, lar As String
    Call calucatemethod00(max2, mid, lar)
    Text1.text = max2
    Text2.text = mid
    Text3.text = lar
这样运行后正常。
    但很奇怪的是我把lar换成sma时
即:Call calucatemethod00(max2, mid, sma)
    Text1.text = max2
    Text2.text = mid
    Text3.text = sma
就报错显示:ByRef参数类型不符。
百思不得其解,这三个参数不是一摸一样的吗? 以前好像也碰到过这样的问题,当时没在意,改了改就过去了,不过再次碰到时就觉得肯定是我们哪里有问题了,请高手指正。

解决方案 »

  1.   

    Public Function method00(max_up As Integer, carname2, carname3 As String)
    Dim strsql As String
    Dim CR As New ADODB.Recordset
    Dim CR1 As New ADODB.Recordset
    Dim CR2 As New ADODB.Recordset
    Dim CR3 As New ADODB.Recordset
    Dim a, b, c, sum, n, i As Integer
    Dim name_1, name_2, name_3 As String
    Dim x(1000) As Integer
    i = 1
            
            CR.CursorLocation = adUseClient
            CR.CursorType = adOpenKeyset
            CR.LockType = adLockOptimistic
            CR1.CursorLocation = adUseClient
            CR1.CursorType = adOpenKeyset
            CR1.LockType = adLockOptimistic
            CR2.CursorLocation = adUseClient
            CR2.CursorType = adOpenKeyset
            CR2.LockType = adLockOptimistic
            CR3.CursorLocation = adUseClient
            CR3.CursorType = adOpenKeyset
            CR3.LockType = adLockOptimistic
            name_1 = frmRecaculate.Combo2.text
            name_2 = frmRecaculate.Combo1.text
            CR.Open "select * from csh轿运车 where 车牌号 ='" & name_2 & "'", cn
            CR1.Open "select * from " & name_1 & " where 型号1 ='大'", cn
            CR2.Open "select * from " & name_1 & " where 型号1 ='中'", cn
            CR3.Open "select * from " & name_1 & " where 型号1 ='小'", cn
            n = CR1.RecordCount + CR2.RecordCount + CR3.RecordCount
                    For b = 1 To CR2.RecordCount
                         If b > 1 Then
                            CR2.MoveNext
                         End If
            
                           For c = 1 To CR3.RecordCount
                               If c > 1 Then
                                  CR3.MoveNext
                               End If 
                              sum = (CR2!长) + 5 * (CR3!长)
                              Dim carname_2(1000), carname_3(1000) As String
                                   If sum < (CR!l + CR!L1 + CR!L5 + 10000) Then
                                      x(i) = sum
                                      carname_2(i) = CR2!型号
                                      carname_3(i) = CR3!型号
                                      i = i + 1
                                   End If
                           Next c
                           CR3.MoveFirst
                    Next b
                    CR2.MoveFirst            Dim j As Integer        '求最大值
                max_up = x(1)
                carname2 = carname_2(1)
                carname3 = carname_3(1)
                For j = 1 To UBound(x)
                   If x(j) > max_up Then
                     max_up = x(j)
                     carname2 = carname_2(j)
                     carname3 = carname_3(j)
                   End If
                Next j
    End Function
      

  2.   

    应该和函数里的代码没关系的,我现在把sma,mid,lar分开定义好像也是可以的
    即:dim sma as string
        dim mid as string
        dim lar as string
    就不知道弄成dim sma,mid,lar as string 为什么会报错
      

  3.   

    基础不牢啊
    dim sma,mid,lar as string 

    dim sma as Variant
    dim mid as Variant
    dim lar as string 
    VB6 不是 C++ .............