首页 > 解决方案 > 使用变量来引用类模块 VBA

问题描述

我正在学习 VBA,但在使用变量引用类模块时遇到问题。所以,我有一个具有此功能的模块 MAIN:

Public sub correr_lista ()
       For i = LBound(lista) To UBound(lista) - 1
             Call verifica (lista (i).time, lista_ficheiros(i + 1).time, lista (i).setor)
       next i
End public

在同一个模块中我有这个功能

Public Sub verifica (time1 As Date, time2 As Date, V_setor As String)
  'Percorre  a lista para ver o tipo de torneira e a sua velocidade
   For a = LBound(listaon) To UBound(listaon)

        If (listaon(a).setor = V_setor) Then

            ' Pergunta à torneira porta qual a sua velocidade
            aux_velocidade(a) = V_setor.getvelocidade(listaon(a).porta)
   next a
End sub

我有类模块 Setor

Public Function getvelocidade(porta As String)

 Dim velocidade As Integer

        For a = LBound(listaSetor) To UBound(listaSetor)

                velocidade = listaSetor(a).get_velocidade(porta)
        Next i

getvelocidade = velocidade
end function 

listSector 列表定义为:

Dim listaSetor () As Object

我们在水龙头类模块

Public Function get_velocidade(n_porta As String)

Dim aux As Double
For i = LBound(porta) To UBound(porta)
         aux = porta(i).velocidade
Next i
 get_velocidade = aux

End Function

门定义为:

Dim porta(1 To 3) As tipo

Public Type tipo
   porta As String
   nome As String
   velocidade As Double
   tipo As String
End Type

出现的错误是该行的方法验证中的无效限定符:

aux_velocidade(a) = V_setor.getvelocidade(listaon(a).porta)

当错误出现时,它会在变量 V_setor 下划线

我该如何解决这个问题?

标签: excelvba

解决方案


推荐阅读