Validating user input for wave name
mshook
I'm creating a function that allows the user to enter the name of an output wave using a simple input dialog, and I want to make sure the user entered a valid wave name before proceeding (note that I'm not concerned about liberal wave names, just truly invalid ones, e.g. ":::"). If the wave name entered is invalid, I want to present the user with the opportunity to re-enter a name without encountering an Igor runtime error message. My first thought was PossiblyQuoteName, but that passes some invalid names through (e.g.
Print PossiblyQuoteName(":::")
returns ':::'). My other ideas are to 1) search the input string for all invalid characters before using it, or 2) use the input string to make the wave in a try-catch block, similar to this: String strWaveName
Do
Prompt strWaveName, "Enter a wave name: "
DoPrompt "Output Wave Name", strWaveName
Try
Make $strWaveName; AbortOnRTE
Catch
Variable err = GetRTError(1) //get and clear the error, since we either try again or quit
If (err != 0)
DoAlert/T="Invalid Wave Name" 1, "You entered an invalid wave name. Would you like to try again?"
If (V_flag != 1) // 1 is yes, 2 is no, 3 (not used here) is cancel
Return -1
EndIf
Continue
EndIf
EndTry
Break
While (1)
Do
Prompt strWaveName, "Enter a wave name: "
DoPrompt "Output Wave Name", strWaveName
Try
Make $strWaveName; AbortOnRTE
Catch
Variable err = GetRTError(1) //get and clear the error, since we either try again or quit
If (err != 0)
DoAlert/T="Invalid Wave Name" 1, "You entered an invalid wave name. Would you like to try again?"
If (V_flag != 1) // 1 is yes, 2 is no, 3 (not used here) is cancel
Return -1
EndIf
Continue
EndIf
EndTry
Break
While (1)
Are there any other/better suggestions out there?
Thanks!
If they're the same, the name is valid.
Maybe also use exists(usersName) to check for a name conflict.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
May 20, 2014 at 03:31 pm - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 20, 2014 at 04:45 pm - Permalink
May 22, 2014 at 11:35 am - Permalink