VBA sin()和cos()问题 [英] VBA sin() and cos() trouble
问题描述
我试图制作一些VBA形式并计算一些简单的值,但是我不明白为什么VBA无法识别Sin()和Cos()函数.例如:我编写了int(),然后VBA将其转换为Int(),但对sin和cos却不一样.而且,在我尝试编译我的代码之后
Im trying to make some VBA form and to calculate some simple values but I dont understand why VBA dosen't recognize Sin() and Cos() functions. For example: I wrote int() and VBA transformed it into Int(), but it doesn't do the same with sin and cos. Moreover, after I'm trying to compile my code
Private Sub btn_exit_Click()
Unload laborator_2
End Sub
Private Sub btn_start_Click()
today.Caption = Date
rnb_val.Caption = Int(Rnd * 90 + 1)
sqrt_val.Caption = Sqr(rnb_val.Caption)
si_val.Caption = sin(rnb_val.Caption * 3.14159 / 180)
co_val.Caption = rnb_val.Caption * 3.1459 / 180
End Sub
我收到此消息:
Run-time error "424" Object required
我是VBA的新手,如果我没有填写所有详细信息,请抱歉.谢谢.
Im new in VBA, so sorry if I didn't write all details. Thank you.
推荐答案
sin&cos不是vba内置的函数.但是,它们内置在excel中,可以通过vba的$ WorksheetFunction $对象作为$ WorksheetFunction.Sin $和$ WorksheetFunction.Cos $访问.您可以在电子表格中使用的所有功能都可以通过这种方式访问.
sin & cos are not functions that are built into vba. They are, however, built into excel and can be accessed through the $WorksheetFunction$ object of vba as $WorksheetFunction.Sin$ and $WorksheetFunction.Cos$. Any functions that you can use in a spreadsheet are accessible this way.
这篇关于VBA sin()和cos()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!