At the start of a user-defined function, I feel that what I should do is, for each passed paramter, check its type and that its value is allowable. Consider pseudo code below:
Code: Select all
WriteFuncLabelCallSequenceToFile(psCallingFuncLabelName, piFlag, psScriptName:="")
{
;===Error check the parameters===
If (psCallingFuncLabelName is not alpha)
MsgBox, The variable %psCallingFuncLabelName% should be type alpha in %A_ThisFunc% (line %A_LineNumber%), but is not.
If (psScriptName is not alpha)
MsgBox, %psScriptName% should be type alpha in %A_ThisFunc% (line %A_LineNumber%), but is not.
If (piFlag is not integer)
MsgBox, %pParam1% should be type integer in %A_ThisFunc% (line %A_LineNumber%), but is not.
if piFlag not between -1 and 1
MsgBox, %piFlag % is not in the range -1 to 1, inclusive.
; more of the function's code here
return
}
Assuming this approach is basically OK, I can see how type checking might work for most types, but not easily for strings (which is what the first 2 type checks above do). What happens if my passed parameter is a combination of chars and spaces - eg., "Here we_are 12345" - how to test that this is a string?
Grateful for any advice, specific to the question, or more generally on checks of this nature.