every time i run this program in VBE i keep getting the message
'Compile Error: expected array' for the two bold lines underneath, please help?
Public Function KnotsToKmPerHr(knots As Double) As Double
Dim Km As Double
KNOTS_TO_KM = 1.852
Km = knots * KNOTS_TO_KM
KnotsToKmPerHr = Km
End Function
Sub CreateFlightPlan()
Dim row As Integer
Dim col As Integer
Dim dblAirSpeed As Double
Dim dblWindSpeed As Double
Dim angle As Double
Dim angle2 As Double
Dim KnotsToKmPerHr As Double
Dim bearing As Double
Dim direction As Double
Dim beta As Double
Dim alpha As Double
col = COL_LEG_BEARING
row = ROW_FIRST_LEG
KnotsToKmPerHr = 1.852
dblAirSpeed = ActiveSheet.Range(CELL_AIRSPEED) ' in knots
AirSpeed = KnotsToKmPerHr(dblAirSpeed)
dblWindSpeed = ActiveSheet.Cells(row, COL_WIND_SPEED)
WindSpeed = KnotsToKmPerHr(dblWindSpeed)
bearing = ActiveSheet.Cells(row, col).Value
While ActiveSheet.Cells(row, col) <> ""
If bearing >= 0 And bearing < 270 Then
angle = -bearing + 90
ElseIf bearing >= 270 And bearing <= 360 Then
angle = -bearing + 450
End If
direction = ActiveSheet.Cells(row, COL_WIND_DIR).Value
If direction > 0 And direction < 270 Then
angle2 = -direction + 90
ElseIf direction >= 270 And direction < 360 Then
angle2 = -direction + 450
End If
angle2 = angle2 + 90
alpha = angle2 + angle
beta = ArcSin((Sin(alpha) * WindSpeed) / AirSpeed)
row = row + 1
Wend
End Sub
Hi
I think there are probable two solution to this,
1) Remove the public function and change the lines from this
AirSpeed = KnotsToKmPerHr(dblAirSpeed)
WindSpeed = KnotsToKmPerHr(dblWindSpeed)
to this
AirSpeed = KnotsToKmPerHr*dblAirSpeed
WindSpeed = KnotsToKmPerHr*dblWindSpeed
OR
2) Remove these two lines
Dim KnotsToKmPerHr As Double
KnotsToKmPerHr = 1.852
This is on the basis that AirSpeed and WindSpeed are declared elsewhere ?
Also, all other calculations seem a waste of time because they only have scope inside the Sub and don't seem to be used for any purpose elsewhere (ie written to the spreadsheet)??
Of course I could be missing something, or this is early in developement !!
MTB