OK. I will look inyo creating unit tests for DB2.
What about minor changes to the code? For example:
Public Function SysvarTok(a As String, Optional n As Integer = 0) As Integer
Dim t As Integer
If Left(a, 1) = "." Then
a = Right(a, Len(a) - 1)
For t = 1 To UBound(sysvar)
If LCase(sysvar(t).Name) = LCase(a) Then SysvarTok = sysvar(t).value
Next t
If n > 0 Then
For t = 1 To UBound(rob(n).vars)
If rob(n).vars(t).Name = a Then SysvarTok = rob(n).vars(t).value
Next t
End If
Else
SysvarTok = val(a)
End If
End Function
Would not it be better to
LCase "a" just once?
LCase in the second loop on rob(n).vars?
Exit a loop once you have a hit?
Skip the first loop if n > 0 since we overwrite SysvarTok in the second loop? ==> Simply switch the loop order
Raise an error if the "a" is not found in sysvars or robot vars? Currently the code ignores the error and returns 0.
Why is there a need to LCase sysvar(I).Name) when this could be done after initializing sysvar?
Looks to me that this LCase is done for each DNA strand of each copy of each robot when starting the sim. Very wasteful.
'---------------------------------------------------------------------------------------
' Procedure : SysvarTok
' Author :
' Date : 07/05/2017
' Purpose :
'---------------------------------------------------------------------------------------
Public Function SysVarTok(a As String, Optional n As Integer = 0) As Integer
10 On Error GoTo func_err
Const FUNC_NAME = MOD_NAME & "SysVarTok"
Dim I As Integer
20 If Left(a, 1) = "." Then
30 a = LCase(Right(a, Len(a) - 1))
40 If n > 0 Then
50 For I = 1 To UBound(rob(n).vars)
60 If LCase(rob(n).vars(I).Name) = a Then
70 SysVarTok = rob(n).vars(I).value
80 Exit Function
90 End If
100 Next
110 End If
120 For I = 1 To UBound(sysvar)
130 If LCase(sysvar(I).Name) = a Then
140 SysVarTok = sysvar(I).value
150 Exit Function
160 End If
170 Next
180 Err.Raise 19999, "", "Unknown SysVar or robot vars: ." & a & " in bot number " & n
190 Else
200 SysVarTok = val(a)
210 End If
220 Exit Function
func_err:
230 Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.source, Err.Description
End Function
Dror