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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kieran04
    New Member
    • Sep 2008
    • 1

    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 CreateFlightPla n()

    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.Ran ge(CELL_AIRSPEE D) ' in knots
    AirSpeed = KnotsToKmPerHr(dblAirSpeed)
    dblWindSpeed = ActiveSheet.Cel ls(row, COL_WIND_SPEED)
    WindSpeed = KnotsToKmPerHr(dblWindSpeed)
    bearing = ActiveSheet.Cel ls(row, col).Value

    While ActiveSheet.Cel ls(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.Cel ls(row, COL_WIND_DIR).V alue

    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(alp ha) * WindSpeed) / AirSpeed)

    row = row + 1

    Wend

    End Sub
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by kieran04
    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 CreateFlightPla n()

    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.Ran ge(CELL_AIRSPEE D) ' in knots
    AirSpeed = KnotsToKmPerHr(dblAirSpeed)
    dblWindSpeed = ActiveSheet.Cel ls(row, COL_WIND_SPEED)
    WindSpeed = KnotsToKmPerHr(dblWindSpeed)
    bearing = ActiveSheet.Cel ls(row, col).Value

    While ActiveSheet.Cel ls(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.Cel ls(row, COL_WIND_DIR).V alue

    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(alp ha) * 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

    Comment

    Working...