03-16-2023, 03:37 PM
Code: (Select All)
ISVALID` = TRUE
FOR LoopCounter = 1 TO LEN(FileName)
FOR LoopCounter1 = 1 TO NumberOfVaildCharacters
IF FileNameParts(LoopCounter) <> Legal(LoopCounter1) THEN ISVALID` = FALSE: EXIT FUNCTION
NEXT LoopCounter1
NEXT LoopCounter
Set the function return value and leave straight away, no need to check it and no need to "set the trap" at each character in the "FileName" to check. This was coded also for more consistency with the function body code that appears before this demonstration.
Also I suggest using a "FOR... NEXT" loop to initialize most of the Legal() array. Because you will have to include uppercase and lowercase letters to check on Linux and MacOS. Filenames on Unix and Unix-like operating systems are case sensitive.