Jump to content

If/Then to force specific user input


---
 Share

Recommended Posts

I have some programs where I need operators to complete some user fields.
See image: Untitled.png

Example PCM: (If I get help here I should be able to figure the other fields If/Then statements).
optest=getRecordHead("u_OperatorName")
if len(optest)<2
            repeat
                        optest=inquireText("Please enter the OPERATOR NAME - YOU DID NOT ENTER IT ON THE RUN SCREEN")
                        setRecordHead("u_OperatorName",optest)
            until len(optest)>2
endif
This If/Then doesn't prevent the user form entering invalid data.
Such as a line of "______" (Underscores) or "---------" (Dashes).
This should be Alpha only and up to to 4 characters.

Are there PCM methods for "Alpha" and or "Numeric" only conditions?

Untitled.png

Link to comment
Share on other sites

I don't use the run screen I control all the inputs with PCM, this file can also control mini-plans if . We avoid typing any chance we can get so the first version is about to be obsoleted in favour of a version that will use barecode scanner.

Here's two versions of this code. It traps the operators until the desired input is put in or cancels the run. In these examples you should find ideas on how you can control it.

This code should execute in any version 2018 or newer but be aware there is some undocumented code in it.
//------xxxx Final Audit------
cancelMess="		Invalid entry, Cancel or No selected.		"+cr()+cr()+cr()+ "		   Do you wish to end the program?		"
nextLoop=false
loopBreak=false
programCancel=false
selectionCheck=true
setupQuestion=""
expectedSerialLength = 16

		curMachID=getRecordHead("procid")
		curPalletID=getRecordHead("fixtid")
		curAuditID=getRecordHead("startcomment")
			//------Start of main loop------
			repeat
				employNum=""
				mach="Final"	
				pall="N/A"
				para=""
				loopBreak=false
		
				//-------------Serial Number Input Loop---------------------
					repeat
						loopBreak=false
						AuditID = inquireText("		Type Serial Number: (Last Entered: "+curAuditID+") "+cr()+cr()+"			  ***Must be "+expectedSerialLength+" digits***		"+cr()+cr()+"		Example: W3OP322210214865")
							if (AuditID == "") or (len(AuditID) <> expectedSerialLength) or (setupQuestion==false) then
								loopBreak=confirm(cancelMess)
									if loopBreak then
										nextLoop=false
										programCancel=true
									endif
							else
								loopBreak=true
								nextLoop=true
							endif
					until loopBreak
									
					//-------------Run Parameter Input Loop---------------------
					if nextLoop then
						repeat
							loopBreak=false
							para=inquireList("Select Run Parameters", "Full Program", "Recheck")
								if (para=="") or (setupQuestion==false) then
									loopBreak=confirm(cancelMess)
										if loopBreak then
											nextLoop=false
											programCancel=true
										endif
								else
									loopBreak=true
								endif
						until loopBreak
					endif

				//Displays the selections and asks if the operator is happy with them
				if programCancel==false
					selectionCheck=executeCode("ICCDialog confirm: 'You selected:"+cr()+cr()+cr()+cr()+"AuditID/Serial:			<u><c:red>"+AuditID+"</u></c>"+cr()+cr()+cr()+"Run Identifier:			<u><c:red>"+para+"</u></c>"+cr()+cr()+cr()+cr()+"Is this correct?' asRichText")
						if selectionCheck==false
							loopBreak=confirm(cancelMess)
									if loopBreak then
										programCancel=true
									endif
						else
							loopBreak=true
						endif
				endif
			until loopBreak
			
		//------Skips to here if Cancel is selected at any point in the selection menu's at program start------
		if programCancel then
			message("You have chosen to cancel the program")
			cncBreak()
		else

			//-----------Sets the run based on selection from Run Parameter Loop
			if (para <> "Recheck") then
				setRunID("FullProgram")
			endif
			
		//-------Sets the header data from the selections chosen by the operator
				setRecordHead("vda_signature",employNum)
				setRecordHead("procid",mach)
				setRecordHead("fixtid","N/A")
				setRecordHead("startcomment",AuditID)
		endif

cancelMess="		Invalid entry, Cancel or No selected.		"+cr()+cr()+cr()+ "		   Do you wish to end the program?		"
nextLoop=false
loopBreak=false
programCancel=false
selectionCheck=true
setupQuestion=""

	
		curMachID=getRecordHead("procid")
		curPalletID=getRecordHead("fixtid")
		curParaID=getRecordHead("startcomment")
			//------Start of main loop------
			repeat
				employNum=""
				mach=""
				pall="N/A"
				para=""
				loopBreak=false
				
					//-------------Employee Number Input Loop(NOT CURRENTLY USED)---------------------
					//repeat
						//loopBreak=false
						//employNum=inquireNumber("What is your employee number? (Must input a valid employee Number)")
							//if (employNum=="") or (employNum<99) then
								//loopBreak=confirm(cancelMess)
									//if loopBreak then
										//nextLoop=false
										//programCancel=true
									//endif
							//else
								//loopBreak=true
								//nextLoop=true
							//endif
					//until loopBreak

					//-------------Machine Number Input Loop---------------------
					//if nextLoop then
						repeat
							loopBreak=false
							mach=inquireList("Choose CNC Machine (Last Entered: "+curMachID+")","745","667","566")
								if mach=="" then
									loopBreak=confirm(cancelMess)
											if loopBreak then
												nextLoop=false
												programCancel=true
											endif
								else
									loopBreak=true
									nextLoop=true
								endif
						until loopBreak
					//endif
					
					//-------------Pallet/Spindle ID Input Loop---------------------
					if (mach == "745") and (nextLoop) then
						repeat
							loopBreak=false
							pall=inquireList("Choose Pallet/Spindle ID (Last Entered: "+curPalletID+")","1","2")
								if pall=="" then
									loopBreak=confirm(cancelMess)
											if loopBreak then
												nextLoop=false
												programCancel=true
											endif
								else
									loopBreak=true
									nextLoop=true
								endif
						until loopBreak
					endif
					
					//-------------Run Parameter Input Loop---------------------
					if nextLoop then
						repeat
							loopBreak=false
							para=inquireList("Select Run Parameters (Last Entered: "+curParaID+")", "Firstoff", "Lastoff", "OIS", "Recheck","Setup","Setup Recheck")
								if (para=="Setup") or (para=="Setup Recheck") then
									setupQuestion=confirm("You have selected Setup or Setup Recheck: "+cr()+cr()+"Setup will run the entire program"+cr()+"Setup Recheck will only run whatever is selected in current selection."+cr()+cr()+"This is NOT to be used for anything other than setting up machines. Are you sure this is what you want? Selecting No will allow you to select again, or cancel the run")
								endif
								if (para=="") or (setupQuestion==false) then
									loopBreak=confirm(cancelMess)
										if loopBreak then
											nextLoop=false
											programCancel=true
										endif
								else
									loopBreak=true
								endif
						until loopBreak
					endif


				//Displays the selections and asks if the operator is happy with them
				if programCancel==false
					selectionCheck=executeCode("ICCDialog confirm: 'You selected:"+cr()+cr()+cr()+cr()+"Machine Number:				<u><c:red>"+mach+"</u></c>"+cr()+cr()+"Pallet/Spindle Identifier:		<u><c:red>"+pall+"</u></c>"+cr()+cr()+"Run Identifier:					<u><c:red>"+para+"</u></c>"+cr()+cr()+cr()+cr()+"Is this correct?' asRichText")
						if selectionCheck==false
							loopBreak=confirm(cancelMess)
									if loopBreak then
										programCancel=true
									endif
						else
							loopBreak=true
						endif
				endif
			until loopBreak
			
		//------Skips to here if Cancel is selected at any point in the selection menu's at program start------
		if programCancel then
			message("You have chosen to cancel the program")
			cncBreak()
		else

			//-----------Sets the run based on selection from Run Parameter Loop
			if (para == "Recheck") or (para == "Setup Recheck") then
				//Do nothing for now
			else
				selectCase para
					case "Firstoff"
					setRunID("FullProgram")
					case "Lastoff"
					setRunID("FullProgram")
					case "Setup"
					setRunID("FullProgram")
					case "OIS"
					setRunID("OIS")
				endSelect
			endif
		
			//-------Sets the header data from the selections chosen by the operator
			setRecordHead("vda_signature",employNum)
			setRecordHead("procid",mach)
			setRecordHead("fixtid",pall)
			setRecordHead("startcomment",para)
		endif
Link to comment
Share on other sites

Unfortunately, I am forced to use the "Input Parameter" dialog box.
Setting a string length like your serial number section, some would just enter 16 characters in a row. ("1234567890123456" or a bunch of underscores, etc...)
Link to comment
Share on other sites

Yeah that Input parameter menu is good for honest people but there's not enough ways to actively control it for us.

I have to assume everybody is going to be lazy and force inputs. Most of our production CMMs we've actually just removed the keyboards from now and I bring one with me if I need to work on it.

Unfortunately PCM doesn't have the best error handling but you can get creative, string length(Equals, Min, max, in-between), the employee number one in the other file looks for a minimum numerical value. All my loops don't allow blanks.

The main loop breaks and either sets the variable programCancel. There's no way for the program to run unless everything is filled out.
Link to comment
Share on other sites

I'm going try to send parameter values to specific text files (I know how to do this part), evaluate with VBS, report a "0" for Ok and a "1" for Not Ok.
Read the text values (0 or 1) (I know how to do this part too) and prompt the user to re-enter the value if new variable = "1".
It will be a single line text file.
At creation it will contain the user input string.
After VBS evaluation, it will be over written to be "0" or "1".
Link to comment
Share on other sites

I am wondering if I can use PCM to run a VBS file?
Edit: Probably have to make the VBS file an EXE file.

If I skip the PCM section for the VBS file, and force the WorkOrderID.txt file to "1", the PCM code executes correctly.
It seems that I can't trigger the VBS file.

This is the PCM code.
idtest=getRecordHead("u_WorkOrderID") //Get value from Input Parameter dialog box
	inspPath = getActualInspectionDir()+"\"
	fileName = "WorkOrderID.txt" //Read WorkOrderID.txt file
	deleteFile(inspPath+fileName)
	addToFile(inspPath+fileName,idtest) //Write new Work Order ID value
		cd=(getActualInspectionDir())
		systemCallWithWait(cd+"\"+"ReadWorkOrder.vbs") //Check for IsNumeric. True (0) or False (1), Write new value to WorkOrderID.txt file
		cd=(getActualInspectionDir())
		my_list=readListFile("WorkOrderID.txt") //Re-read WorkOrderID.txt file, "0" = True, '1" = False
		WorderID=val(getParameterNamed(my_list,1)) //Extract text line1
if WorderID==1 then //If False, propmt user to re-renter value 
		idtest=inquireText("Please enter a propper Work Order Number.") //(Need a loop to test for string length of 7 or greater)
          setRecordHead("u_WorkOrderID",idtest)
endif
This is the VBS code. (ReadWorkOrder.vbs)
sFolder = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\") - 1)
'msgbox(sFolder) 'for testing

Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(sFolder & "\WorkOrderID.txt")

Dim sWorkOrderID
sWorkOrderID = file.ReadLine
'msgbox(sWorkOrderID) 'for testing, display Work Order ID
'file.close
If IsNumeric(sWorkOrderID) = true Then
		'msgbox("Ok") 'for testing, So I know if True
		'Set fso = CreateObject("Scripting.FileSystemObject")
		Set file = fso.OpenTextFile(sFolder & "\WorkOrderID.txt",2 ,True)
		sWorkOrderID = "0"
		file.WriteLine sWorkOrderID
		file.close
	Else
		'msgbox("Not Ok") 'for testing, so I know If False
		'Set fso = CreateObject("Scripting.FileSystemObject")
		Set file = fso.OpenTextFile(sFolder & "\WorkOrderID.txt", 2, True)
		sWorkOrderID = "1"
		file.WriteLine sWorkOrderID
		file.close
End if
Link to comment
Share on other sites

Can you simply use systemCall() or systemCallwithWait()? they are for running external programs I'm not sure if they will run a VBS file.
Link to comment
Share on other sites

Hi,
you can check if optest is Alphabetic, Numeric or AlphaNumeric by
// check if optest is Alphabetic
executeCode("|checkStr| checkStr:=true. '" + optest + "' do: [ :char | char isAlphabetic ifFalse: [checkStr:=false].]. ^checkStr")

// check if optest is Numeric
executeCode("|checkStr| checkStr:=true. '" + optest + "' do: [ :char | char isDigit ifFalse: [checkStr:=false].]. ^checkStr")

// check if optest is AlphaNumeric
executeCode("|checkStr| checkStr:=true. '" + optest + "' do: [ :char | char isAlphaNumeric ifFalse: [checkStr:=false].]. ^checkStr")
Here "checkStr:=true." is the initial value and the code
do: [ :char | char isAlphabetic ifFalse: [checkStr:=false].
iterates over all characters of the string and set the parameter checkStr to false if one character does not fulfill the condition. Finally "^checkStr" returns the value of checkStr.
Link to comment
Share on other sites

Does this code force the user to enter an Alpha/Numeric value?
// check if optest is AlphaNumeric
executeCode("|checkStr| checkStr:=true. '" + optest + "' do: [ :char | char isAlphaNumeric ifFalse: [checkStr:=false].]. ^checkStr")
Or will it simply pass if the value is Alpha, Numeric or Alpha/Numeric?
In my case, the user will enter a string such as "M001".

I had thought I could catch this as below.
optest=getRecordHead("u_OperatorName")
executeCode("|checkStr| checkStr:=true. '" + optest + "' do: [ :char | char isAlphaNumeric ifFalse: [checkStr:=false].]. ^checkStr")
if checkStr==False
            repeat
                        optest=inquireText("Please enter your Stamp ID. Example: M000.")
                        setRecordHead("u_OperatorName",optest)
            until checkStr==True
endif
Link to comment
Share on other sites

Please sign in to view this quote.

You can enter whatever you want. If you enter an alphanumeric string like Teststring1 it returns true.
If you enter an non-alphanumeric string like Teststring_1 it returns false, since the character "_" is included.

Your code will not work in the present way. The parameter checkStr is only defined and exists inside the executeCode(...) command which just compiles some smalltalk-code. But it es possible to use the same name for a new PCM-Parameter outside of executeCode(...).
The following should work:

  repeat
       optest=inquireText("Please enter your Stamp ID. Example: M000.")
       checkStr=executeCode("|checkStr| checkStr:=true. '" + optest + "' do: [ :char | char isAlphaNumeric ifFalse: [checkStr:=false].]. ^checkStr")
              until checkStr==true
                             setRecordHead("u_OperatorName",optest)
Link to comment
Share on other sites

I modified it a little, I only want the prompt when checkStr equals false.
optest=getRecordHead("u_OperatorName")
  repeat
       checkStr=executeCode("|checkStr| checkStr:=true. '" + optest + "' do: [ :char | char isAlphaNumeric ifFalse: [checkStr:=false].]. ^checkStr")
			if checkStr==false
					optest=inquireText("Please enter your Stamp ID. Example: M000.")
			endif
              until checkStr==true
                             setRecordHead("u_OperatorName",optest)
Used as in your example made the user prompt come up regardless of what the user entered in a previous text box.

Much appreciation for your input!
Link to comment
Share on other sites

  • 2 months later...
---
Finally getting a chance to implement this and it doesn't work anymore.
optest=getRecordHead("u_OperatorName")
  repeat
       checkStr=executeCode("|checkStr| checkStr:=true. '" + optest + "' do: [ :char | char isAlphaNumeric ifFalse: [checkStr:=false].]. ^checkStr")
			if checkStr==false
					optest=inquireText("Please enter your Stamp ID. Example: M000.")
			endif
              until checkStr==true
                             setRecordHead("u_OperatorName",optest)
Ini File related to u_OperatorName.
[u_OperatorName]
name=Operator
editMode=true
runMode=false
editable=true
selectiveList=false
kValue=20002
Link to comment
Share on other sites

---
Made an option without the executeCode function.
  • Reads the current u_OperatorName using getRecordHead
  • Goes through the string, treating it like an array of characters, verifying each character is alphanumeric
  • If all characters are alphanumeric, the string is good to go!
  • If they are not all alphanumeric...
    • alert user the operator name is invalid
    • prompt for new operator name (if no input is entered, cancel the run altogether)
    • set u_OperatorName using setRecordHead, in case things work out
    • start over checking the newly input name
Does not verify a specific length for the operator name, aside from being non-zero.

Try this:

optest = getRecordHead("u_OperatorName")

repeat
    // Start assuming we're good, in each repeat of this loop.
    checkStr = true
    
    // Loop through the character array (string) character by character
    //   - logical AND between true and the result of isAlphaNumeric on the current character
    //   - if it's ever false, there's an invalid character, ask for input
    for chr_index = 1 to len(optest)
        checkStr = checkStr and getParameterNamed("optest", chr_index).isAlphaNumeric
    next chr_index
    
    if len(optest) == 0 then
        checkStr = false
    endif
    
    // If an invalid character was found, prompt for input. Could also be: checkStr == false
    if not checkStr then
        message("Operator Name Invalid.")
        optest = inquireText("Please enter your Stamp ID. Ex: M000")
        setRecordHead("u_OperatorName", optest)
        
        // If no input was given, cancel run completely. (Also break out of possibly infinite loop.)
        if (len(optest) == 0) or (optest == "") then
            message("Input not entered. Cancelling run.")
            cncBreak()
        endif
    endif
until checkStr

alphanumeric user input.txt

Link to comment
Share on other sites

 Share

×
×
  • Create New...