VBA编程:对象创建、集合使用与调试技巧
在VBA编程中,创建和使用自定义对象及集合是非常实用的技能,同时掌握调试工具也能帮助我们更高效地解决程序中的问题。下面将详细介绍这些内容。
为CAsset类编写方法
在CAsset类模块中,可以编写NewPrice函数来计算新价格。该函数需要传入三个参数:discountType(折扣类型)、currentPrice(当前价格)和amount(折扣值)。以下是具体的代码:
' function to calculate new price
Public Function NewPrice(discountType As Integer, _
currentPrice As Currency, _
amount As Long) As Currency
If amount >= currentPrice Then
NewPrice = currentPrice
Exit Function
End If
Select Case discountType
Case 1 ' by percent
If amount > 50 Then
amount = 50
End If
NewPrice = currentPrice - ((currentPrice * amount) / 100)
Case
超级会员免费看
订阅专栏 解锁全文
10

被折叠的 条评论
为什么被折叠?



