Class 如何在vbforexcel中创建类

Class 如何在vbforexcel中创建类,class,excel,vba,Class,Excel,Vba,您好,我正在尝试在vb中创建一个类,并尝试在没有任何值的情况下实例化该类 Private lat As Double Private lon As Double Public Property Get Longitud() As Double Longitud = lon End Property Public Property Get Latitud() As Double Latitud = lat End Property Public Property Let Longitud(

您好,我正在尝试在vb中创建一个类,并尝试在没有任何值的情况下实例化该类

Private lat As Double
Private lon As Double

Public Property Get Longitud() As Double

Longitud = lon

End Property
Public Property Get Latitud() As Double
Latitud = lat

End Property
Public Property Let Longitud(ByVal longi As Double)

Longitud = lon

End Property

Public Property Let Latitud(ByVal lati As Double)

Latitud = lat
End Property
当我试图举例时

Dim cord As Coordenadas
Set cord = New Coordenadas
cord.Latitud = 40.30416667
cord.Longitud = 0.22583333

我看不到跳线有任何变化

您的Let属性没有正确分配作为参数传递的值。 其内容应如下:

Private lon As Double
'

Public Property Let Longitud(ByVal longi As Double)

    lon = longi

End Property
Let
应将值分配给您的私有变量(Lon),而
Get
应检索存储在该变量内的值


作为一个补充,如果你给你的私人财产加上一个特殊的后缀,这将对你有很大帮助。例如普隆和普拉特。这种方法更容易从参数和属性中识别变量。

您应该重新查看“属性Let”过程:它们是做什么的?他们应该怎么做?哦,谢谢,我注意到当我传递的值是longi时,是lon!!这是我的错,不客气。如果你有解决的办法,考虑把它作为你自己问题的答案。但是,请准备好将问题“过于本地化”或甚至删除,因为除了帮助您在自己的代码中找到bug之外,它可能没有什么意义(除了可能每个人都至少有一次因为这些琐事而绊倒)。(你也可以读一下这方面的文章)好的,亚历克斯:再次感谢你在最后几行给我提供的所有信息