Page 1 of 1

[SOLVED] How do I put the last four characters of a field (string) in a new variable?

Posted: Thu Jul 19, 2018 11:37 pm
by karmacomposer
I tried searching all over the internet for the answer and just could not find it.

I have a SSN field and I need to grab the last four digits and append it to another field (making a complete account number).

The SSN field already has a script for proper formatting of the SSN (thank you to the person who helped me with that) and it uses RawKeyDown to do its magic. Do I add this there, after the RawKeyDown, on CloseField or do I put it in the script of the account # field? My thought is, I don't want to break what the auto-formatting is doing.

Also, when reading back the data, how do I hide all but the last four digits with either a "*" or a bullet?

Thank you for your help.

Mike

Re: How do I put the last four characters of a field (string) in a new variable?

Posted: Thu Jul 19, 2018 11:44 pm
by bogs
If the ssn is formatted as you say, you could always just set the itemDelimiter (dictionary) to - or / or whatever you used for the formatting, then get item 3 of the field, which should be the last 4 numbers. You could also (if it isn't actually formatted) grab chars 6 to 9 of the field (characters, keyword, dictionary).

The code would look like -

Code: Select all

// formatted ssn...
set the itemDelimiter to "-"
put item 3 of field "yourSsnField" into tmpLastFour
// your code for what you want to do with that...
Selection_003.png
Formatted item 3...
...and unformatted -

Code: Select all

put char 6 to 9 of field "yourSsnField" into tmpLastFour
// your code for what you want to do with that...
Selection_004.png
Unformatted char...

Re: How do I put the last four characters of a field (string) in a new variable?

Posted: Fri Jul 20, 2018 1:39 am
by karmacomposer
Thank you. That was perfect! The 1st option worked a treat.

Mike