472,143 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

cant fix my Compile error: expected array for VBE excel, need help very new at this??

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
Sep 17 '08 #1
1 5020
MikeTheBike
639 Expert 512MB
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
Sep 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Tiernan | last post: by
5 posts views Thread by Andrew V. Romero | last post: by
1 post views Thread by Amen | last post: by
5 posts views Thread by Carmine Cairo | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.