Jump to content

Back to my Blacklist of Characters using PCM.


---
 Share

Recommended Posts

Well, I found out why I am not changing the partbinc value, I have several mini plans and in the inspect file it is being written for each mini plan used as a separate partbinc line.

So, now I am using the file "protheadpara" to obtain the value I want to check for invalid characters and set the partbinc value because this value changes regardless of the mini plan (I think Richard Shomaker led me down this path. 😉 )

Except I am stuck on indexing the list from the protheadpara file.

PCM doesn't like this line: "currentLine = fileLines[i]". It reports an error that fileLines[i] is not defined.

Any assistance is appreciated.

// Define list of invalid characters/sequences
NOT_ALLOWED_LIST = list("~", "`", "!", "@", "$", "%", "^", "&", "*", "(", ")", "+", "=", "{", "}", "[", "]", "|", ":", ";", "'", "<", ">", ",", ".", "/", "\\", "?", "--", "__")
NOT_ALLOWED_LIST_NAME = "NOT_ALLOWED_LIST"

// Build full file path (no suffix)
inspPath = getActualInspectionDir() + "\\"
fileName = inspPath + "protheadpara"

// Read file into a list
fileLines = readListFile(fileName)

// Initialize variable
sernotest = ""

// Loop through lines to find partnbinc
for i = 1 to fileLines.size
    currentLine = fileLines[i]  // Correct way to access list element?
    if inStr(currentLine, "partnbinc,") <> 0 then
        // Extract value after comma
        sernotest = strElement(2, ",", currentLine)
        i = fileLines.size + 1 // Exit loop
    endif
next i

// Backup original value
sernotest2 = sernotest

// Validation loop
repeat
    invalid_found = false

    // Check against NOT_ALLOWED_LIST
    for not_allowed_index = 1 to NOT_ALLOWED_LIST.size
        this_not_allowed_str = getParameterNamed(NOT_ALLOWED_LIST_NAME, not_allowed_index)
        attempt = inStr(sernotest, this_not_allowed_str)

        if attempt <> 0 then
            message("Invalid character '" + this_not_allowed_str + "' found in input '" + sernotest + "'. Please re-enter a valid value.")
            sernotest = inquireText("Please enter the correct \"Serial Number or numeric counter value\".")
            invalid_found = true
            not_allowed_index = NOT_ALLOWED_LIST.size + 1 // Force exit from for-loop
        endif
    next not_allowed_index

    // Additional explicit check for consecutive dashes or underscores
    if inStr(sernotest, "--") <> 0 or inStr(sernotest, "__") <> 0 then
        message("Invalid sequence '--' or '__' found in input '" + sernotest + "'. Please re-enter a valid value.")
        sernotest = inquireText("Please enter the correct \"Serial Number or numeric counter value\".")
        invalid_found = true
    endif

until invalid_found == false

// Final assignment
setRecordHead("u_partnbinc", sernotest)

 

Link to comment
Share on other sites

Edit:

" I have several mini plans and in the inspect file it is being written for each mini plan used as a separate partbinc line." should be " I have several mini plans and in the inspset file it is being written for each mini plan used as a separate partbinc line."

Link to comment
Share on other sites

Well your error message says it all. It's not defined. You have a List-object in "fileLines", and to access each index in that list you can use getParameterNamed(var,index)

To define fileLines[i] you need to, as an example do someting like this:

for i = 1 to fileLines.size
	fileList[i] = getParameterNamed(fileList,i)
next i

And that seems counter intuitive in this case...

 

Anyway, you can simplify all of this a lot. Here is a example:

//Read partnbinc
for i = 1 to fileLines.size
    if inStr(getParameterNamed(fileLines,i), "partnbinc,") <> 0
       dirtyRecordHead = strElement(2, ",", getParameterNamed(fileLines,i))
       i = fileLines.size + 1 // Exit loop
    endif
next i

//Remove illegal characters
cleanRecordHead = ""
for i = 1 to len(dirtyRecordHead)
	selectCase getParameterNamed(dirtyRecordHead.asArray,i).asUppercase.asInteger
		case 48 to 57, 65 to 90 //Include 0-9, a-z and A-Z
			cleanRecordHead = cleanRecordHead + chr(getParameterNamed(dirtyRecordHead.asArray,i))
	endSelect
next i
setRecordHead("partnbinc",cleanRecordHead)

 

Edited
Can't spell, slightly retarded...
  • Like! 3
Link to comment
Share on other sites

 Share

×
×
  • Create New...