具体程序如下:
Private Sub Form_Load()
    Dim id(3) As Integer
    For i = 0 To 3
        id(i) = i
    Next i
    If Inicom(Command1, id) = True Then
        msg "ok"
End SubPrivate Function Inicom(cmd() As CommandButton, id() As Integer) As Boolean
On Err GoTo comErr
    For Each i In cmd
        i.Enabled = False
    Next i
    For Each i In id
        cmd(i).Enabled = True
    Next i
comErr:
    msg Err.Number & Err.Description
End Function
但老抱错,说类型不匹配,不知是什么原因,请各位指点!

解决方案 »

  1.   


    Private Sub Form_Load()
        Dim id(3) As Integer
        Dim i As Integer
        For i = 0 To 3
            id(i) = i
        Next i
        If Inicom(Command1, id) = True Then
            MsgBox "ok"
        End If
    End SubPrivate Function Inicom(cmd As Variant, id() As Integer) As Boolean
        On Err GoTo comErr
        Dim i As CommandButton
        Dim j
        For Each i In cmd
            i.Enabled = False
        Next i
        For Each j In cmd
            cmd(j).Enabled = True
        Next j
        Exit Function
    comErr:
        MsgBox Err.Number & Err.Description
    End Function
      

  2.   


    Private Sub Form_Load()
        Dim id(3) As Integer
        Dim i As Integer
        For i = 0 To 3
            id(i) = i
        Next i
        If Inicom(Command1, id) = True Then
            MsgBox "ok"
        End If
    End SubPrivate Function Inicom(cmd As Variant, id() As Integer) As Boolean
        On Err GoTo comErr
        Dim i As CommandButton
        Dim j
        For Each i In cmd
            i.Enabled = False
        Next i
        For Each j In cmd
            cmd(j).Enabled = True
        Next j
        Inicom = True
        Exit Function
    comErr:
        MsgBox Err.Number & Err.Description
    End Function加上了:Inicom = True