[Ri...] Posted October 21 Share Posted October 21 This brings up too many errors, but I think I need to know how to use "while" or if I can with PCM. (AI generated) Any help is appreciated. Blocked_Chars = "~`!@#$%^&*()+={}[]|:;',<>./?" setRecordHead("u_PartNumb",PN) Part_Numb = getRecordHead("u_PartNumb") // or however you retrieve the input i = 1 while (i <= length(Blocked_Chars)) currentChar = substring(Blocked_Chars, i, 1) if (instr(Part_Numb, currentChar) > 0) message("Invalid character '" + currentChar + "' found in part name.") stop() endif i = i + 1 endwhile  Link to comment Share on other sites More sharing options...
[Ri...] Posted October 21 Author Share Posted October 21 Im learning Copilot isnt very good at PCM. Now I am trying GTP5, but it is still full of errors. What are some of you using for AI and PCM? Link to comment Share on other sites More sharing options...
[Ma...] Posted October 21 Share Posted October 21 I don't know if while is supported. I found: for next if else endif if endif repeat until selectCase endSelect Calypso_02_PCM 1 Link to comment Share on other sites More sharing options...
[Ri...] Posted October 21 Author Share Posted October 21 The goal is to create a blacklist of characters when read from variables. u_PartNumb is just one example. Link to comment Share on other sites More sharing options...
[Ma...] Posted October 21 Share Posted October 21 (edited) I would use FOR cycle and to find occurence of char use "inStr()" From posted link to pcm manual it's on page 1-65 and 1-142 Do you want to just find occurence or substitute / remove them? Edited October 21 1 Link to comment Share on other sites More sharing options...
[No...] Posted October 22 Share Posted October 22 Please sign in to view this quote. I still prefer "NI" over AI. Less hallucinations😄 Couldn't you get the same result with repeat / until? You only need to modify the condition and put it at the end: i=1 repeat currentChar=..... if (instr(..... nessage(.... stop() //???? --> cncBreak() ? endif i=i+1 until (i > length(Blocked_Chars))  1 Link to comment Share on other sites More sharing options...
[Ri...] Posted October 22 Author Share Posted October 22 I do have to go with repeat, Calypso v2017 doesn't support what I posted. Of course that was after trying AI. Link to comment Share on other sites More sharing options...
[Ri...] Posted October 22 Share Posted October 22 // Edit this list with what you don't want NOT_ALLOWED_LIST = list("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "+", "=", "{", "}", "[", "]", "|", ":", ";", "'", ",", "<", ">", ".", "/", "?") NOT_ALLOWED_LIST_NAME = "NOT_ALLOWED_LIST" Part_Numb = getRecordHead("u_PartNumb") // Begin searching for not-allowed strings for not_allowed_index = 1 to NOT_ALLOWED_LIST.size repeat // Get the first not-allowed string to check this_not_allowed_str = getParameterNamed(NOT_ALLOWED_LIST_NAME, not_allowed_index) this_not_allowed_len = len(this_not_allowed_str) // Attempt to find the not-allowed string // - if found, will be non-zero // - if not found, will be zero attempt = inStr(Part_Numb, this_not_allowed_str) // If the not allowed string was found, // - from: the start of the original string (1) // - to: the attempt index (minus 1 to not include the 1st character) // - PLUS // - from: attempt index + the length of the search string // - to: the end of what remains if attempt <> 0 then Part_Numb = subStr(Part_Numb, 1, attempt - 1) + mid(Part_Numb, attempt + this_not_allowed_len) endif until attempt == 0 // repeat for all not-allowed strings next not_allowed_index Someone else wrote this for me when I was trying to strip specific phrases out of header information. I would think this would work for you as well. 3 Link to comment Share on other sites More sharing options...
[An...] Posted October 22 Share Posted October 22 (edited) (Edit: Please sign in to view this username.  & I were writing the same response! He beat me to the reply 😅) I believe the solution you're looking to create exists already in my post here: You will need to: fill out the rest of the NOT_ALLOWED_LIST with characters that are not allowed I did about half of Blocked_Chars Could sneak a " character in with qm() or chr(34), among other methods... replace sourceStr with something more meaningful to your use case  Updated for 2025: // Edit this list with what you don't want NOT_ALLOWED_LIST = list("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")") NOT_ALLOWED_LIST_NAME = "NOT_ALLOWED_LIST" sourceStr = inquireText("Enter something to be filtered:") // Begin searching for not-allowed strings for notAllowedIndex = 1 to NOT_ALLOWED_LIST.size repeat // Get the first not-allowed string to check thisNotAllowedStr = getParameterNamed(NOT_ALLOWED_LIST_NAME, notAllowedIndex) thisNotAllowedLen = len(thisNotAllowedStr) // Attempt to find the not-allowed string // - if found, will be non-zero // - if not found, will be zero attempt = inStr(sourceStr, thisNotAllowedStr) // If the not allowed string was found, // - from: the start of the original string (1) // - to: the attempt index (minus 1 to not include the 1st character) // - PLUS // - from: attempt index + the length of the search string // - to: the end of what remains if attempt <> 0 then sourceStr = subStr(sourceStr, 1, attempt - 1) + mid(sourceStr, attempt + thisNotAllowedLen) endif until attempt == 0 // repeat for all not-allowed strings next notAllowedIndex // Output display(sourceStr) See attached for the above code 😇 general.txt Edited October 22 Richard Shomaker beat me to the punch 2 1 Link to comment Share on other sites More sharing options...
[Ri...] Posted October 22 Share Posted October 22 Please sign in to view this username.  I couldn't have done it without you though, so many thanks once again for the piece of code that you wrote for me. 🙂 1 Link to comment Share on other sites More sharing options...
[Ri...] Posted October 23 Author Share Posted October 23 Thank you all!! 1 Link to comment Share on other sites More sharing options...
[Ri...] Posted October 31 Author Share Posted October 31 I have been working on this with the supplied code above. So far this code is working. Thank you to all! //Character Black List NOT_ALLOWED_LIST = list("~", "`", "!", "@", "$", "%", "^", "&", "*", "(", ")", "+", "=", "{", "}", "[", "]", "|", ":", ";", "'", ",", "<", ">", ".", "/", "\", "?", "--", "__") NOT_ALLOWED_LIST_NAME = "NOT_ALLOWED_LIST" //End Character Black List //Begin WOID validation // Initial input idtest = getRecordHead("u_WorkOrderID") repeat invalid_found = false for not_allowed_index = 1 to NOT_ALLOWED_LIST.size this_not_allowed_str = getParameterNamed(NOT_ALLOWED_LIST_NAME, not_allowed_index) attempt = inStr(idtest, this_not_allowed_str) if attempt <> 0 then message("Invalid character '" + this_not_allowed_str + "' found in input '" + idtest + "'. Please re-enter a valid value.") idtest = inquireText("Please enter the correct ""Work Order ID"".") setRecordHead("u_WorkOrderID_Corrected", idtest) invalid_found = true not_allowed_index = NOT_ALLOWED_LIST.size + 1 // Force exit from for-loop endif next not_allowed_index until invalid_found == false // Prompt for Stamp ID after successful validation idtest = inquireText("Please enter the correct ""Work Order ID"".") setRecordHead("u_WorkOrderID", idtest) //End WOID validation  1 Link to comment Share on other sites More sharing options...
[Ri...] Posted October 31 Author Share Posted October 31 (edited) Curious, I thought "setRecordHead" would physically change the value in the "Printer header data" dialog box. Â Edited October 31 Link to comment Share on other sites More sharing options...
[Ri...] Posted October 31 Author Share Posted October 31 After running the program, it is physically changed. Link to comment Share on other sites More sharing options...
[Ri...] Posted October 31 Author Share Posted October 31 And just like that, the code no longer functions. Â Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in