Welcome Guest

Pages: 1
Scan Statement
LouisMackey111PostSeptember 28, 2018, 18:18
Newbie
Posts: 14
Registered:
November 8, 2014, 19:45
Normal topicScan Statement

Can Someone give me a tutorial on the scan statement?

I'm Trying to remove "Traditional" from the composer field (I'll handle it later by putting it first in the list of composers)

I have this:

Clear Variable 10 and 5 other fields

Scan up to string "Traditional" (case insensitive) in field Composer, result to Variable 15 remainder to Variable 14. Set state
Dump snapshot, system, named variables. Show Action Test State and Call Stack Prompt after scan for Trad (Black)
if true
Set named variable 'Traditional' to "Yes"
Find "Traditional" in Variable 14, remove it and everything before, set state
Append the Variable 14 field to Variable 15
Find all matches for regular expression "‡\ *‡" in field Variable 15, replace with "‡" to field Variable 15
Trim Variable 15 (SP) [Leading] [Trailing]
Copy the Variable 15 field to the Composer field
endif
Copy the Composer field to Variable 3
Dump snapshot, system, named variables. Show Action Test State and Call Stack Prompt after if (Black)

Clear Variable 10 and 5 other fields

Which works fine if there is a Traditional in the list but does not if its not in the list; clearly I'm misunderstanding how to use scan.

2MR2PostSeptember 28, 2018, 18:36
Avatar photo
Administrator
Posts: 2083
Registered:
August 23, 2012, 19:27
Normal topicRe: Scan Statement

This is a little hard to read as plain text. Can you please export the action (select it in the action manager, right click, Export), zip it up and send it to us at aupport@2manyrobots.com. It'll be far easier to look at. Also, if you can send the text for one Composer field which contains 'traditional'. I can take a detailed look sometime tomorrow.

2MR2PostSeptember 29, 2018, 11:54
Avatar photo
Administrator
Posts: 2083
Registered:
August 23, 2012, 19:27
Normal topicRe: Scan Statement

I've has another look at the code. The issue is more than likely that 'Scanner-Scan Up to String' will scan to the end of the string if the pattern is not found. The test state is set to true if any characters were scanned. Technically the statement is 'Scan Up to String or End of String'. The entire string will be in the 'result' and the 'remainder' will be empty.

The following will work:

Scan up to string "Traditional" (case insensitive) in field Composer, result to Variable 15 remainder to Variable 14. Set state
Scan string "Traditional" (case insensitive) in field Variable 14 (ignore SP), result to Variable 9 remainder to Variable 10. Set state

Basically you want to ignore the action test state after the first Scanner statement. It will return true unless the Composer field was empty or started with Traditional. ie.'no characters were scanned'.

With the above two lines, the action test state will be true if and only if Traditional was found anywhere in Composer.

Variable 15 will be empty or will contain all text before Traditional
Variable 14 will be empty or will contain all text after Traditional
Variable 9 will be empty or will contain Traditional
Variable 10 will be empty or will contain all text after Traditional

I guess I have to be a little more verbose in the documentation....sigh 🙁

I can't tell what you actually have in the Composer field when Traditional is present. However, if the word is consistently delimited you can easily remove any 'item' containing Traditional and place it at the start of the list. For example if the composer list is delimited by the multi-value delimiter.

Test if the list in field Composer delimiter "\m" has an item containing case insensitive "Traditional", remove, item->V15
if true
Add "\v15" to the start of the list in field Composer delimiter "\m"
endif

The assumption is that the above code is being run 'groupwise'.

REMEMBER that the mailer strips backslash characters. The code may not make any sense if viewed in an email.

LouisMackey111PostOctober 6, 2018, 16:10
Newbie
Posts: 14
Registered:
November 8, 2014, 19:45
Normal topicRe: Scan Statement

Sorry, fell off world there for a while....

Any way I have solved my problem (Had quite a bit of down time this past week); you are right the scan statement works fine when the search term was/is found, but goes a bit nuts (well, my logic goes a bit nuts anyway) when its not in the search string.

so anyway after some trials and several errors I came up with:

Clear Variable 10 and 5 other fields

Return first match for regular expression "\ATraditional\Z" in field Composer to field Variable 10
if true
Set named variable 'Do Composer Search' to "No"
else
Set named variable 'Do Composer Search' to "Yes"
Return first match for regular expression "Traditional" in field Composer to field Variable 10
if true
Scan up to string "Traditional" (case insensitive) in field Composer, result to Variable 15 remainder to Variable 14. Set state
if true
Set named variable 'Traditional' to "Yes"
Find "Traditional" in Variable 14, remove it and everything before, set state
Append the Variable 14 field to Variable 15
Find all matches for regular expression "‡\ *‡" in field Variable 15, replace with "‡" to field Variable 15
Trim Variable 15 (SP) [Leading] [Trailing]
Copy the Variable 15 field to the Composer field
endif
endif
endif

which seems to do what I wanted, I then do the same thing for Anon. and I'm Happy....

Thank you for your support and suggestion(s)

Pages: 1
Mingle Forum by Cartpauj | Version: 1.1.0beta | Page loaded in: 0.013 seconds.