The ADDBS function was originally implemented by Thomas Ganss:
function AddBs(tcString)
return iif(right(m.tcString,1)=="\", m.tcString, m.tcString+"\")
Version with strict typing by Olaf Doschke:
Function AddBS()
Lparameters tcString
Do Case
Case PCount()=0 && alternative: Vartype(tcString)="L" and !tcString
Error 1229
Case VarType(tcString)<>"C"
Error 11
Case tcString == ""
Return ""
EndCase
m.tcString = Alltrim(m.tcString)
Return iif(Right(m.tcString,1)=="\", m.tcString, m.tcString+"\")
EndFunc
Let's see if the online compiler can compile that...No, pcount() is missing.
Also Pcount()>1 should be handled of the runtime, because lparameters is too short for more than one.
The May 15 update includes PCOUNT() and works like expected.
This looks good. You don't need to do all the strong typing, let that to the compiler:
function AddBs
TPARAMETERS tcString as string
return iif(right(m.tcString,1)=="\", m.tcString, m.tcString+"\")
This version enables you to detect at compile time if you do something like AddBS(24). While this approach is good for this function, it has the disadvantage for other functions that you can't pass less parameters than needed, like you can if you have declared this function with LPARAMETERS.