首页 > 解决方案 > 类模块结构,在不同层次上获得相同的属性

问题描述

我正在尝试与我的整个公司一起构建一个类模块,如下所示:

结构

现在我知道如何通过这个答案来实现这一点。

问题是我在一个计划区域,它将安排每个人的工作和轮班,所以我需要添加日期和时间表......我想建立一个除以每一分钟的全天时间表,所以 1440 分钟。

如果我要编写具有我需要的属性的 2 个类,例如 Auxiliar Time 和 Workers on the shift,我可以从任何其他类中调用它们而不会相互混淆吗?

例如,我的目标是能够总结一天的 Aux 时间、一组分钟数,具体取决于部门或特定位置的部门。

我知道这写起来会很乏味,但是有可能实现这样的事情吗?

我的代码现在调用具有不同属性的代理,例如他的位置、服务、名称和区域。通过提供他的 ID,您可以填写这些信息,如果您为班级提供日期,您可以获得他的日程安排、部门和评论。

我知道这一切都必须改变,但我只需要知道我在这里想要完成的事情是否可能,或者有什么比我的初始结构更有效的方法。

我的代码如下:

公司类别:

Option Explicit
Private ID As Object
Property Get clAgente(ByVal Key As String) As clAgente
    With ID
        If Not .Exists(Key) Then .Add Key, New clAgente
    End With
    Set clAgente = ID(Key)
End Property
Public Property Get Count() As Long
    Count = ID.Count
End Property
Public Property Get Keys() As Variant
    Keys = ID.Keys
End Property
Private Sub Class_Initialize()
    Set ID = CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate()
    Set ID = Nothing
End Sub

代理类:

Option Explicit
Private Centro As String
Private Servicio As String
Private Nombre As String
Private DirNeg As String
Private Agrup As String
Private Fechas As Object
Property Get Business() As String
    Business = DirNeg
End Property
Property Let Business(ByVal param As String)
    DirNeg = param
End Property
Property Get Group() As String
    Group = Agrup
End Property
Property Let Group(ByVal param As String)
    Agrup = param
End Property
Property Get Location() As String
    Location = Centro
End Property
Property Let Location(ByVal param As String)
    Centro = param
End Property
Property Get Service() As String
    Service = Servicio
End Property
Property Let Service(ByVal param As String)
    Servicio = param
End Property
Property Get Name() As String
    Name = Nombre
End Property
Property Let Name(ByVal param As String)
    Nombre = param
End Property
Property Get clHorarios(ByVal Key As Date) As clHorarios
    With Fechas
        If Not .Exists(Key) Then .Add Key, New clHorarios
    End With
    Set clHorarios = Fechas(Key)
End Property
Private Sub Class_Initialize()
    Set Fechas = CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate()
    Set Fechas = Nothing
End Sub
Public Property Get Count() As Long
    Count = Fechas.Count
End Property
Public Property Get Keys() As Variant
    Keys = Fechas.Keys
End Property

最后,

日期类:

Option Explicit
Private m_Horario As String
Private m_Modo As String
Private m_Coment As String
'Aquí creamos la propiedad Horario para la clase Fecha
Public Property Get Horario() As String
    Horario = m_Horario
End Property
Public Property Let Horario(ByVal param As String)
    m_Horario = param
End Property
'Aquí creamos la propiedad Modo para la clase Fecha
Public Property Get Modo() As String
    Modo = m_Modo
End Property
Public Property Let Modo(ByVal param As String)
    m_Modo = param
End Property
'Aquí creamos la propiedad Coment para la clase Fecha
Public Property Get Comentario() As String
    Comentario = m_Coment
End Property
Public Property Let Comentario(ByVal param As String)
    m_Coment = param
End Property

对此事的任何见解将不胜感激。

标签: excelvbaclass

解决方案


一句话:是的


[...] 我可以在不互相打扰的情况下从任何其他班级打电话给他们吗?

请记住,类只是结构并且在实例化并分配给可以被范围内的任何代码行复制和修改的对象变量之前是没有意义的。因此,任何类是否可以访问该变量取决于范围,而您最终是否会陷入混乱取决于您和我们的设计。


[...] 有可能实现这样的目标吗?

如果您还不知道可以做这件事,那么在做这件事之前,您将有大量的学习要做。


对此事的任何见解将不胜感激。

没有什么你以前没听过,你还没有做:阅读、尝试和学习


推荐阅读