将参数传递给属性时如何防止自动转换?

时间:2018-04-18 10:40:11

标签: vba

当我尝试将字符串(testString = "10")参数传递给带有货币参数(ByVal newCash as Currency)的属性时,为什么它不会失败?我不希望这种自动转换。怎么预防呢?如何禁用它?

Model课程模块

Option Explicit

Private m_cash As Currency

Public Property Let Cash(ByVal newCash As Currency)
    m_cash = newCash
End Property

Test课程模块

Option Explicit

Public Sub Test()
    Dim modelObj as Model
    Dim testString as String

    Set modelObj = New Model
    testString = "10"

    modelObj.Cash = testString
End Sub

0 个答案:

没有答案