@Environment Question Reloaded Please Help URGENT

I have a button carrys the code: (with other fields)

@Environment("InvoiceNumber"; @Text(InvoiceNumber));
@PostedCommand([FileCloseWindow]);
@PostedCommand([Compose]; ""; "Customer Log")

and the field has the code:

envvar := @Environment("InvoiceNumber");
@If(envvar != ""; @SetEnvironment( "InvoiceNumber"; ""); "");
envvar;

What i need is, if the button is pressed and the field already has an invoice number (which it would have) for a suffix of a, or if it has already a suffix of a then b and if it has already a suffix of b then c etc etc, but only one letter to be present at any time

Qwaletee gave me this, but it does not work:

envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );
letters := "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
base := @Left(envVar;6);
priorLetter := @Right(envVar;1);
newLetter := @Replace(priorLetter; "dummy" : letters; letters : "error- ran out of alphabet!");
base + newLetter

Any ideas URGENT




DavidAbbottAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RanjeetRainCommented:
What problem are you facing. The code seems to be correct.
qwaleteeCommented:
Let's try to to debug this...


envvar := @Environment("InvoiceNumber");
@Prompt([OK]; "envvar"; envvar);
@SetEnvironment( "InvoiceNumber"; "");
@Prompt([ok]; "shortcut decision when no suffix yet"; @If(@Length(envVar = 6; "@Return (final result): " + envVar + "a"; "no shortcut, continuing") );
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );
letters := "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
base := @Left(envVar;6);
@Prompt([ok];"base";base);
priorLetter := @Right(envVar;1);
@Prompt([ok];"priotLetter"; priorLetter);
newLetter := @Replace(priorLetter; "dummy" : letters; letters : "error- ran out of alphabet!");
@Prompt([ok];"newLetter";newLetter");
@Prompt([ok];"final result w/o shortcut"; base + newLetter);
base + newLetter

HemanthaKumarCommented:
David,

I think I already gave you a simplified soln for the problem

anyway I repeat it here (There was a minor error in previous formula that I gave) here is the corrected one

envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );
alphas := "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
idx  := @If(@Ends(envvar;alphas); @member(@Right(envvar; 1); alphas); 0);
final := @leftback(envvar;1) + @if( idx > 0; @Subset(@Subset(alphas;idx+1);-1);  "");
final

~Hemanth
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

DavidAbbottAuthor Commented:
qwaletee

it is cutting off one of the numbers and not adding the first letter in the first instance
HemanthaKumarCommented:
do you ever hear me ?
qwaleteeCommented:
HemanthaKumar,
That's simplified?  OK, so it is 7 lines instead of 8.  That's only due to desnity.  M original code was meant to be readiable.  Wanna see it dense?  Only 4 lines.  Can you get it tighter without repeating @Environment or letters/alphas list?

envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
letters := @If(@Length(envVar = 6; @Return(envVar + "a"); "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z");
@Left(envVar;6) + @Replace(@Right(envVar;1); "dummy" : letters; letters : "error- ran out of alphabet!");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qwaleteeCommented:
DavidAbbott,
> qwaletee

> it is cutting off one of the numbers and not adding the first letter in the first instance
Could you please give me the eaxt sequence of prompt messages?  For example, I would expect something like:

envvar: 123456
shortcut decision when no suffix yet: @Return (final result): 123456a

I know it is tedious, but I can't tell where it cuts it off unless I know all the steps it takes!

In the case of 123456a, it should result in the following prompts:
envvar: 123456a
shortcut decision: no shortcut
base: 123456
priorLetter: a
newLetter: b
final result w/o shortcut: 123456b

HemanthaKumarCommented:
your formula is hardcoded for a fixed length, mine doesn't rely on that and mostly generic code.. I am not telling your code is wrong.. If that is so then try to answer the previous thread where you proposed the soln.. I am trying to give him a new direction in this new question...
qwaleteeCommented:
I figured that the current format is 6-dgot plus 1 alpha.  To be really certain, you would have to use an @Matches check for either 6 digits alone, or 6 digits plus one alpha.  In either case, at that point, the break occurs after 6.  If there was any change, it cold be to 7 numbers (a problem for my code), or to a number/letter mix (a problem  for your code).
HemanthaKumarCommented:
Let us not argue on this.. Let David work it out.
DavidAbbottAuthor Commented:
Hi

Sorry, just got back, the following code bums out on my machine and says too many functions etc

envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
letters := @If(@Length(envVar = 6; @Return(envVar + "a"); "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z");
@Left(envVar;6) + @Replace(@Right(envVar;1); "dummy" : letters; letters : "error- ran out of alphabet!");

so does:

envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );
alphas := "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
idx  := @If(@Ends(envvar;alphas); @member(@Right(envvar; 1); alphas); 0);
final := @leftback(envvar;1) + @if( idx > 0; @Subset(@Subset(alphas;idx+1);-1);  "");
final




qwaleteeCommented:
Left a paren off: letters := @If(@Length(envVar = 6     )     ; @Return(envVar + "a"); "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z");


But that code is essentially identical to what I gave you last time.  You the version with the embedded prompts, s we can debug this thing, OK?!
DavidAbbottAuthor Commented:
OK this code produces the following results:

With the invoice number being 328072

envvar = 328072
base = 328072
priorletter = 2
newletter = 2
final result = 328072

>>CODE<<

envvar := @Environment("InvoiceNumber");
@Prompt([OK]; "envvar"; envvar);
@SetEnvironment( "InvoiceNumber"; "");
@Prompt([ok]; "shortcut decision when no suffix yet"; @If(@Length(envVar = 6; "@Return (final result): " + envVar + "a"; "no shortcut, continuing") );
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );
letters := "a":"b":"c":"d":"e":"f":"g":"h":"i":"j":"k":"l":"m":"n":"o":"p":"q":"r":"s":"t":"u":"v":"w":"x":"y":"z";
base := @Left(envVar;6);
@Prompt([ok];"base";base);
priorLetter := @Right(envVar;1);
@Prompt([ok];"priotLetter"; priorLetter);
newLetter := @Replace(priorLetter; "dummy" : letters; letters : "error- ran out of alphabet!");
@Prompt([ok];"newLetter";newLetter");
@Prompt([ok];"final result w/o shortcut"; base + newLetter);
base + newLetter
DavidAbbottAuthor Commented:
Oh no, I am in trouble, no solution
DavidAbbottAuthor Commented:
Correction on that code produce:

envvar = 328072
base = 328072
priorletter = 2
newletter = 2
final result = 3280722

sorry
DavidAbbottAuthor Commented:
OK, worked on it and i think it is completed. From my understanding the problem bit was:

@If(@Length(envVar = 6); @Return(envVar + "a"); CONTINUE );

As it was completely ignoring the logic in the arguement and as such just continued on regardless, hence the adding of the last number if it did not have an alpha.

Most other code for some reason ignored the logic and skipped the condition after much trail and error, this following line of code replaced the above, and it worked:

@If(!@Ends(envVar;letters); @Return(envVar + "a"); CONTINUE );

Thanks for the help,


DavidAbbottAuthor Commented:
both you guys (qwaletee & HemanthaKumar) helped greatly and i obtained understanding from both sets of answers, but there can only be one main answered and one assisted acceptance, so on balance i think qwaletee came out on top this time.

Thanks to you both
qwaleteeCommented:
I got it!


Change:
@If(@Length(envVar = 6); @Return(envVar + "a"); CONTINUE );   ...into...
@If(@Length(envVar) = 6; @Return(envVar + "a"); CONTINUE );

Misplaced parenthesis on @Length.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.