CheckName - returns 0 for illegal names?

I am using CheckName when users enter a new wave name in a dialog box to make sure that they put the correct name format for the wave (most of our users are new to Igor so they tend to enter illegal names e.g. names with space or names starting with a number). 

is there a way to do the name check in my case? Thank you!

print checkname("WaveTest 2",1)
  0
print checkname("1WaveTest 2",1)
  0
print checkname("WaveTest",1)
  0

 

All these wave names are valid wave names, but liberal ones. If you want to derive a non-liberal wave name from it, you should use CleanupName first and then UniqueName.

Thank you very much. I didn't realize that liberal names also include names starting with a number. So from your suggestion I use this instead to check for the non-liberal name:

print Stringmatch(WName,CleanupName(WName,0))

Or should I just ignore this and let the users use whatever names they want now (they use Igor6 and Igor8)? I use wave references entirely in my codes. In this case will there be any circumstances when liberal name will cause problems?

When I have a choice for my developments of packages that others will use, I always force non-liberal wave names. Life is so much easier on the other side of programming. In your case, I might handle this in this way: When the user types an enter key in the input box, capture the input string, clean up the name and make it unique, and put the proper wave name up for confirmation.

Thank you! I've alway stuck with non-liberal names too. Not sure about other people these days.

So below is what I came up with.

Function /T SLP_Util_CheckNameDialog(ExpWName)
    //Return empty string ("") to flag that the process is to be terminated (user clicked 'Cancel')
    //Return original name (the original wave is to be overwritten).
    //Return a new unique name (create a new wave)
   
    String ExpWName
    String ExpWName_New=""
   
    If (CheckName(ExpWName,1))//Check whether duplicate
        DoAlert /T="Duplicate wave name." 2,"Duplicate wave name ("+ExpWName+"). Overwrite the wave?"
//      V_flag =    1:  Yes clicked.
//                  2:  No clicked.
//                  3:  Cancel clicked.
        If (V_flag==1) //(YES - overwrite)
            ExpWName_New=ExpWName
        ElseIf (V_flag==2) //(NO - change name)
            Do
                ExpWName_New=cleanupname(uniqueName(ExpWName,1,0),0)
                Prompt ExpWName_New,"A new name is suggested below, or you may enter another name:"
                DoPrompt "",ExpWName_New
                If (V_Flag==1) //Cancel
                    ExpWName_New=""
                ElseIf (CheckName(ExpWName_New,1)) //duplicate?
                    DoAlert 0,"Still a duplicate name"
                Elseif (!Stringmatch(ExpWName_New,CleanupName(ExpWName_New,0))) //is not non-liberal?
                    DoAlert 0,"The name chosen is not valid."
                EndIf
               
            While ((CheckName(ExpWName_New,1)||!Stringmatch(ExpWName_New,CleanupName(ExpWName_New,0)))&&!stringmatch(ExpWName_New,""))
            //If user still entered duplicate name or non-liberal name, and user didn't click Cancel
        Elseif (V_flag==3)
            ExpWName_New=""
        EndIf
    Endif
   
    Return ExpWName_New
End

 

You should use cmpstr instead of stringmatch as the latter supports wildcard characters and that is not what you want here IMHO.

 

Function Dostuff()

    print !cmpstr("a", "*")
    print stringmatch("a", "*")
End

gives

•dostuff()
  0
  1

 

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More