运行此代码时,出现语法错误。我无法理解原因。
我粘贴了我所有的代码。如果你需要,我可以添加数据。
我想编写递归代码以在时间限制下找到所有可能的飞行死记硬背。
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