【发布时间】:2021-10-13 08:15:53
【问题描述】:
如题,我用VBA写了一个函数,但是参数没有传入函数。 这是我的代码:
非常感谢你
Function Solar_altitude_angle() As Single
'Declare
Dim n As Integer
Dim Longtitude As Single
Dim Latitude As Single
Dim Altitude As Single
Dim LSM As Integer
Dim LST As Single
Dim ET As Single
Dim H As Single
Dim AST As Single
Dim i_SolarDeclination As Single
Dim s_Gama As Single
'Equation time
n = DateDiff("d", "01/01/2021", ThisWorkbook.Worksheets("Room_Load").Range("D62"))
Longtitude = ThisWorkbook.Worksheets("Room_Load").Range("E61")
Latitude = ThisWorkbook.Worksheets("Room_Load").Range("B61")
Altitude = ThisWorkbook.Worksheets("Room_Load").Range("G61")
LSM = 105 'oE Greenwich
LST = ThisWorkbook.Worksheets("Room_Load").Range("H62")
i_SolarDeclination = 23.45 * Sin((n + 284) / 365 * 2 * 3.14159)
s_Gama = ((n - 1) / 365) * 2 * 3.14159
ET = 2.2918 * (0.0075 _
+ 0.1868 * Cos(s_Gama) _
- 3.2077 * Sin(s_Gama) _
- 1.4615 * Cos(2 * s_Gama) _
- 4.089 * Sin(2 * s_Gama))
AST = LST * 24 + ET / 60 + (Longtitude - LSM) / 15
H = 15 * (AST - 12)
Solar_altitude_angle = (Application.Asin(Cos(Longtitude) * Cos(i_SolarDeclination) * Cos(H) + _
Sin(Longtitude) * Sin(i_SolarDeclination))) * 180 / 3.1412
End Function
如上图,在watches窗口中显示变量无效。
【问题讨论】:
-
@KostasK。谢谢,这里是代码
-
该函数不接受任何参数
Solar_altitude_angle()。您需要在括号()之间声明它们。 -
例如
Solar_altitude_angle(ByVal someValue as Long, ByVal anotherValue as String, [...]) As Single。 -
如果你想一想,...... 它不起作用, 单独,没有任何关于你实际做了什么的澄清描述,现在没有工作,比较没用。所以,请编辑您的问题并说明您究竟尝试了什么,以及您对它不起作用, 的确切含义
标签: vba parameter-passing