Solved

@Environment Problem

Posted on 2003-10-24
15
207 Views
Last Modified: 2013-12-18
I have a form that has a button which creates a duplicate document in order to save on rekeying etc.

One of the fields is an invoice number and this need to have a letter put to the end of the number everytime this  button is pressed and a new documnet is created

I am working off Environment fields in order to create the new doc, but i can't get the InvoiceNumber Field to take on the new letter that should be assigned to it, the code i have tried is as follows:

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

@If(@Ends(@Environment("InvoiceNumber");"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");@Right(@SetEnvironment("InvoiceNumber";"");7); @Right(@SetEnvironment("InvoiceNumber";"");6));  

Any help please
0
Comment
Question by:DavidAbbott
  • 6
  • 4
  • 3
  • +1
15 Comments
 
LVL 31

Expert Comment

by:qwaletee
ID: 9614542
Here's your problem: you reset the environment variable before you use it!

Your second line nakes the variable blank, butthen you try to use the variable in fifth line!!
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9614572
envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
endsInLetter := @Ends(envVar;"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");
sizeToGet := @If(endsInLetter;7;6)
@Right(envVar;sizeToGet)
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9614593
Here is the modified code

envvar := @Environment("InvoiceNumber");
envvar


@If(@Ends(@Environment("InvoiceNumber");"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");@Right(@SetEnvironment("InvoiceNumber";"");7); @Right(@SetEnvironment("InvoiceNumber";"");6));  


~Hemanth
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9614639
Of course, I don't think you are really dong this the right way anyway.

1) You should use inheritance to transfer values, instead of environment vaiables

2) Where are you SETTING the value of this environment value to start with -- why would it not always be missing (blank)?

3) The whole 6 v. 7 business makes no sense to me.  Let's say the "main" invoice number is a six-digit number, and you are appending a single letter.  So, if there is NO letter on the end, you want the whole thing, and then you want to add a letter. If there IS a letter on the end, you want to take the whole thing with the letter.  At least, that's what your code says. Most likely, you want to do the opposite -- make sure you get the first 6 characters nomatter what, always dropping the last letter, then add a new letter on the end.  the new letter will depend on the previous letter -- a if there was none, b if a, c if b, etc.  Do I understand what you WANT correctly?  he code woudl eb as follows:

envvar := @Environment("InvoiceNumber");
@SetEnvironment( "InvoiceNumber"; "");
@If(@Length(enVar = 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(enVar;6);
priorLetter := @Right(envVar;1);
newLetter := @Replace(priorLetter; "dummy" : letters; letters : "error- ran out of alphabet!");
base + newLetter
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9614643
I believe it is two piece of code ? Am I right ? Anyway The second line of code also has some problems

envvar := @Environment("InvoiceNumber");
envvar


@If(@Ends(@Environment("InvoiceNumber");"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");@Right(@Environment("InvoiceNumber");7); @Right(@Environment("InvoiceNumber");6));  
(@SetEnvironment("InvoiceNumber";"");
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 9614934
You seem not to care about multiple users on multiple databases on multiple servers doing the same thing at the same time, hence creating duplicate documents (not replication conflicts). Well, that's not the issue here, is it? ;-)

Suggested ways to solve the problem, prioritized:
1. use @DbLookup to find existing documents and adapt the invoice number (if a unique key is required)
2. store the latest invoice number in the original document
3. anything else
4. ... or this ...
....
9999. use environment vars

0
 

Author Comment

by:DavidAbbott
ID: 9615561
None of the above works, i will try to make my problem a bit clearer.

The 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;

@If(@Ends(@Environment("InvoiceNumber");"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");@Right(@SetEnvironment("InvoiceNumber";"");7); @Right(@SetEnvironment("InvoiceNumber";"");6));  

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

Cheers Guys
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9616109
This will be the code to do that

envvar := @Environment("InvoiceNumber");
@If(envvar != ""; @SetEnvironment( "InvoiceNumber"; ""); "");
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(a;alphas); @member(@Right(envvar; 1); alphas); 0);
@leftback(envvar;1) + @if( idx > 0; @Subset(@Subset(alphas;idx+1);-1);  "");
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9616773
The code I gave earlier will do that, assuming a 6 charcater (no letter suffix) or 7 characer with one letter suffix) invoice number.

Can you confirm that invoice numbers are 6+1 character, i.e., 135791, 135791a, 135791b, etc.?

Only problem was, I had a typo, now fixed:

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
0
 

Author Comment

by:DavidAbbott
ID: 9796328
still a problem with this,
0
 

Author Comment

by:DavidAbbott
ID: 9796346
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );

Something wrong with this line I believe
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9884516
David I recd your mail.. din't see it for past 1 week

If you want me to take a look at your form send it to me I will take a look at it. Zip if before you send with minimal design for the form to work.

0
 
LVL 31

Accepted Solution

by:
qwaletee earned 500 total points
ID: 9884548
Change from
@If(@Length(envVar = 6; @Return(envVar + "a"); CONTINUE );
to
@If(@Length(envVar) = 6; @Return(envVar + "a"); CONTINUE );


It was the missing ) after @Length(envar
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9884552
(We alredy covered this in the other question)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now