F
Felice
Guest
I need to see if the characters at the end of a string are a zip code or zip+4. If there is no zip or zip+4 at the end of this string, then this address is rejected. I don't understand why when I get to the dash character, "-", which is asci 45, my noZip becomes TRUE right here. I am returning a "Yes" from the fnIsDash function, but I leave the loop at that point.
Related to this problem -- I would like to use a regular expression to see if my string is a zip code, it would be "NNNNN-NNNN" or "NNNNN" where N is any digit. But from my research, I didn't see robust regular expression functionally in Progress. Is that true?
Continue reading...
Related to this problem -- I would like to use a regular expression to see if my string is a zip code, it would be "NNNNN-NNNN" or "NNNNN" where N is any digit. But from my research, I didn't see robust regular expression functionally in Progress. Is that true?
Code:
FUNCTION fnisNumeric RETURNS LOGICAL (INPUT cCharacter AS CHARACTER) FORWARD.
FUNCTION fnisDash RETURNS LOGICAL (INPUT cCharacter AS CHARACTER) FORWARD.
DEFINE VARIABLE location AS CHARACTER NO-UNDO.
DEFINE VARIABLE zipPlus4Temp AS CHARACTER NO-UNDO.
DEFINE VARIABLE noZip AS LOGICAL NO-UNDO.
DEFINE VARIABLE cThisChar AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTemp AS CHARACTER NO-UNDO.
DEFINE VARIABLE iTemp AS INTEGER NO-UNDO.
location = "124 State Road Mechanicsburg PA 17050-3156".
zipPlus4Temp = SUBSTRING (location, length(location) - 9, 10).
MESSAGE "zipPlus4Temp " + zipPlus4Temp VIEW-AS ALERT-BOX.
noZip = FALSE.
DO iTemp = 1 TO LENGTH(zipPlus4Temp):
IF noZip EQ TRUE THEN LEAVE.
cThisChar = SUBSTRING(zipPlus4Temp,iTemp,1).
MESSAGE STRING(iTemp) + " this char " + cThisChar VIEW-AS ALERT-BOX.
IF iTemp GE 1 AND iTemp GE 5 THEN
IF NOT(fnIsNumeric(cThisChar)) THEN noZip = TRUE.
//noZip becomes true here
IF iTemp EQ 6 THEN
IF NOT(fnIsDash(cThisChar)) THEN noZip = TRUE.
IF iTemp GE 7 AND iTemp GE 10 THEN
IF NOT(fnIsNumeric(cThisChar)) THEN noZip = TRUE.
END.
MESSAGE SUBSTITUTE("zipPlus4Temp &1 is &2",zipPlus4Temp, noZip).
FUNCTION fnIsNumeric RETURNS LOGICAL (i_cc as CHARACTER):
RETURN ASC(i_cc) GE 48 AND ASC(i_cc) LE 57.
END FUNCTION.
FUNCTION fnIsDash RETURNS LOGICAL (i_cc as CHARACTER):
MESSAGE SUBSTITUTE("The character being passed is &1",i_cc) VIEW-AS ALERT-BOX.
MESSAGE "the ascii value of the character being passed is " + STRING(ASC(i_cc)) VIEW-AS ALERT-BOX.
RETURN ASC(i_cc) EQ 45.
END FUNCTION.
Continue reading...