Jump to content

How to use "while" in PCM


---
 Share

Recommended Posts

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

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

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
  • Like! 1
Link to comment
Share on other sites

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))

 

  • Like! 1
Link to comment
Share on other sites

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

// 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. 

  • Like! 2
Link to comment
Share on other sites

(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
Richard Shomaker beat me to the punch
  • Like! 1
  • Awesome! 1
Link to comment
Share on other sites

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. 🙂 

  • Thank you! 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...