このコードを実行すると、構文エラーが発生します。理屈が理解できません。
すべてのコードを貼り付けます。必要に応じて、データを追加できます。
再帰コードを書き、時間の制約の下で考えられるすべての飛行ルートを見つけたいと考えています。
find_route 関数は、停止条件が満たされるまで、それ自体で再度実行する必要があります (flight_time>480)。
Function find_route(a As Integer, b As Integer) 'a start node, b start time
flight_time = 0
route(0) = a
l = 0
If flight_time <= 480 Then
If temp_flight_time(a, b) + flight_time <= 480 Then
l = l + 1
route(l) = next_destination(a, b)
flight_time = temp_flight_time(a, b) + flight_time
find_route(route(l),flight_time)'*******syntax error at this row******
End If
Else
Cells(7, 1).Select
For i = 0 To 30
ActiveCell.Value = route(i)
ActiveCell.Offset(0, 1).Select
Next
Cells(1, 1).Select
Exit Function
End If
End Function
Function temp_flight_time(a As Integer, b As Integer)
temp_flight_time = get_flight_time(a, next_destination(a, b))
End Function
Function get_flight_time(a As Integer, b As Integer) 'a from, b to
Cells(2, 1).Select
Dim ae As Integer
Dim be As Integer
For i = 1 To 50
ae = ActiveCell.Value 'From
be = ActiveCell.Offset(0, 1).Value 'To
If a = ae And b = be Then
get_flight_time = ActiveCell.Offset(0, 4).Value 'Flight Time
Exit For
Else
ActiveCell.Offset(1, 0).Select
End If
Next
End Function
Function next_destination(a As Integer, b As Integer)
Cells(2, 1).Select
Dim ae As Integer
Dim be As Integer
For i = 1 To 50
ae = ActiveCell.Value 'To
be = ActiveCell.Offset(0, 2).Value 'Departure
If a = ae And b <= be Then
next_destination = ActiveCell.Offset(0, 1).Value
Exit For
Else
ActiveCell.Offset(1, 0).Select
End If
Next
End Function