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
I got this message:
Run-time error "424" Object required
Im new in VBA, so sorry if I didn't write all details. Thank you.
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.
Check the names that you have given to your labels on the form - they must match exactly the names in the code. I got the same error by naming the si_val label sival instead.