Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) Can this code be shortened? (Read 2405 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Can this code be shortened?
Jun 8th, 2006 at 2:07pm
Print Post Print Post  
I have a field, Billing_Code, which can contain multiple text codes.  Based on the particular code the user enters, certain things need to happen.  Can this code be shortened?

Code
Select All
IF Billing_Code="T" OR Billing_Code="Q" OR Billing_Code="A" OR Billing_Code="B" OR Billing_Code="C"
THEN {action} 



  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Can this code be shortened?
Reply #1 - Jun 8th, 2006 at 2:34pm
Print Post Print Post  
It's not really shorter, but I often use something like the following because I find it easier to maintain:

Code
Select All
var vList as String

    vList = "T;Q;A;B;C"
    If @FindStringArray(vList, Billing_Code) > -1
    {
	  ... do stuff
    }
 



By doing it this way, I can easily adjust the list.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Can this code be shortened?
Reply #2 - Jun 8th, 2006 at 2:36pm
Print Post Print Post  
Infinity wrote on Jun 8th, 2006 at 2:07pm:
I have a field, Billing_Code, which can contain multiple text codes.  Based on the particular code the user enters, certain things need to happen.  Can this code be shortened?

Code
Select All
IF Billing_Code="T" OR Billing_Code="Q" OR Billing_Code="A" OR Billing_Code="B" OR Billing_Code="C"
THEN {action} 





Yes.
Code
Select All
if(@instr("TQAB", Billing_Code) > 0)
{
  // Take Action
}
 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Can this code be shortened?
Reply #3 - Jun 8th, 2006 at 2:45pm
Print Post Print Post  
Super!  Thank you both, those are very useful.
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Can this code be shortened?
Reply #4 - Jun 21st, 2006 at 1:34pm
Print Post Print Post  
I'd like to adapt Mark's test statement:
Code
Select All
if(@instr("TQAB", Billing_Code) > 0) 


to check a different field for any of 14 4-digit numbers (it's a text field holding numeric characters).  This is different from the easy "TQAB" structure.  Can this be done?  Would I use semicolons or some other separator?

Once I get this into Sesame I can use Erica's code, but right now I'm cleaning up Q&A, pre-translation.

Right now my code reads:
Code
Select All
IF #4950="3500" OR #4950="6472" OR #4950="3444"
OR #4950="3481" OR #4950="3751" OR #4950="3915"
OR #4950="2897" OR #4950="3939" OR #4950="4029"
OR #4950="2318" OR #4950="3907" OR #4950="2075"
OR #4950="2834" OR #4950="4883"
	THEN
	{
	   // action
	} 



Thanks in advance.
  

**
Captain Infinity
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Can this code be shortened?
Reply #5 - Jun 21st, 2006 at 1:44pm
Print Post Print Post  
Yes it can be shortened, but there should be some sort of delimiter in the source string. Can you post what the source string looks like? Also, it is probably better to make these improvements in Sesame as per Erika's approach. If you change it in Q&A, you will likely want to change it again in Sesame to take advantage of some of the more efficient functions available in Sesame.

Are you trying to shorten code to get past the Q&A code size limitation?
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Can this code be shortened?
Reply #6 - Jun 21st, 2006 at 2:13pm
Print Post Print Post  
Quote:
Yes it can be shortened, but there should be some sort of delimiter in the source string. Can you post what the source string looks like?

I'm not sure what you're asking.  The field being tested is a billing code field (customer number).  If any of those 14 codes are entered a message box pops up with special instructions for the user.

You're probably right about just leaving it as is in Q&A and then changing it in Sesame.

Quote:
Are you trying to shorten code to get past the Q&A code size limitation?

Somewhat.  I have purchased John Dow's marvelous DTFDOCTR and DTFSPECS utilities and they have been very helpful in cleaning up my Q&A programming.  My program's sizes do have rather high percentages, but I haven't hit the limit yet.

My main problem is the programming structure.  Erika has taught me a lot about how a program should look in order to make sense of it, things that I did not know when I first wrote the Q&A programming.  The first time I tried an (experimental) translation of my Workorder and Invoice databases I was dismayed by the way the programming looked in Sesame.  You know how with Q&A you only have that little F6 box to work with - everything ran together.  It was totally baffling, especially since Sesame changed all my well-documented field numbers into field names.  John's utilities allowed me to extract all my programming into files I can edit with a text editor and then import back into Q&A.  Once that's done I will translate again, and when the field numbers change to field names I expect things will look a lot better in Sesame.  And then at that point I can begin shredding the heck out of it.

I still have yet to take the advanced Sesame programming classes, so in the meantime I'm reworking my Q&A programming, getting a refresher of how these databases work "under the hood", and making lots of notes for future tweaks.

This one particular piece of code is not very important.  I was just wondering it the @INSTR function could be used to test against multiple-character strings.

Thanks for your help.
  

**
Captain Infinity
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Can this code be shortened?
Reply #7 - Jun 21st, 2006 at 3:21pm
Print Post Print Post  
Change fhe field names in Q&A before translating/importing into Sesame.

Q&A wil change the programming references for you and result in Sesame will be immediately readable and familiar.  If you change Element names in Sesame, you will need to search and redo programming.

Use Sesame naming conventions.  Do not use any reserved words like DATE, see Programming Guide, pages 283-285.

I usually restrict my names to InitialCapsWithNoSpacesStartingWithALetterFollowedByLettersAndNumbersWithNoOtherCharacterTypes.
Then it is easy to modify labels by inserting spaces, but programming will be good.

You may still need to change programing for things like multiple values in XL functions, but that is not really related to namechanges, except that names inside quotes in XL statements will still need to be changed.  But that will happen anyway.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Can this code be shortened?
Reply #8 - Jun 22nd, 2006 at 7:27pm
Print Post Print Post  
Thanks for the advice Bob!  I've got most of that under my belt but a reminder never hurts.

Do you know if the @INSTR function will accept a separated series of characters?  Such as:
Code
Select All
IF(@INSTR("13;427;956;386", Billing_Code) > 0) 

to check the Billing Code field for the values 13 or 427 or 956 or 386?

I suppose I could try an experiment, see if Q&A chokes on it.  Then I'll know.  Undecided
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Can this code be shortened?
Reply #9 - Jun 22nd, 2006 at 7:44pm
Print Post Print Post  
Results:  Q&A happily accepts the syntax.  But the condition is met for any value, not just the ones specified.  Oh well.  It was worth a shot.
  

**
Captain Infinity
Back to top
IP Logged
 
walt
Member
*
Offline



Posts: 48
Joined: Nov 30th, 2002
Re: Can this code be shortened?
Reply #10 - Jun 22nd, 2006 at 10:21pm
Print Post Print Post  
Quote:
Yes it can be shortened,


Mark, could you please provide us with a code example of how it can be shortened? I ran into the same thing Infinity did.

Thanks.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Can this code be shortened?
Reply #11 - Jun 22nd, 2006 at 11:54pm
Print Post Print Post  
As I said in my original post - it depends on having a delimiter.

You will have to excuse that I do not have Q&A on my laptop - running Linux, so I will have to write this in simplified psuedocode:

Code
Select All
// Place all the numbers to check in a single variable (or hidden field in Q&A). Do this only once, if possible.
// Separate them with semicolons.
MyField = "3500;6472;3444;3481;3751;3915;2897;3939;4029;2318;3907;2075;2834;4883"

// Then, where ever the check has to occur (CheckField is the same as Infinity's field #4950)
cf = CheckField + ";"
if(@instr(MyField, cf) > 0) then
  // Do Stuff
endif
 




I don't have a Q&A manual here, so I may the args to "@instr" reversed. The semicolons are not completely necessary so this could even be shortened to:
Code
Select All
MyField = "3500;6472;3444;3481;3751;3915;2897;3939;4029;2318;3907;2075;2834;4883"
if(@instr(MyField, CheckField) > 0) then
  // Do Stuff
endif
 



So long as you know that all of the number to be check are of the same length and thereby cannot contain one another.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Can this code be shortened?
Reply #12 - Jun 23rd, 2006 at 1:11am
Print Post Print Post  
I have Q&A on my laptop and this worked for me:

Code
Select All
>#1:If @Instr("1234;5678;9000;4000;5000;", #1 + ";") > 0 Then #2 = "Yes" 



I have two fields. If I type one of the numbers in the list into #1, I get "Yes" in #2. If the number I type is not in the list, I don't. Note that the last value in the list has a trailing semicolon. The last value won't work otherwise.

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Can this code be shortened?
Reply #13 - Jun 23rd, 2006 at 2:57am
Print Post Print Post  
In Erika's example, I noticed that if #1 = "78", #2 would still show "Yes". So, I tweaked it a bit. Wink

Building on Erika's idea on how to deal with Mark's note of caution...

You could, not only use a trailing semicolon, but also use a leading semicolon. This way you could be absolutely sure that the number you are checking is not just matching the end of another one.

Try something like this:
Code
Select All
>#1:If @Instr(";1234;5678;9000;4000;5000;", ";" + #1 + ";") > 0 Then #2 = "Yes" else #2 = "No" 



PS: I tested this, and does produce the desired result.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Can this code be shortened?
Reply #14 - Jun 23rd, 2006 at 11:57am
Print Post Print Post  
I've found that this method needs quite a bit of tweaking to be truly reliable. That's why, in Sesame, I always use @FindStringArray instead of @InStr. Because it knows how to manage the values separately. Q&A doesn't have this function, so you need to have very consistent values to make the @InStr method dependable. Carl's addition of a begin marker is certainly a step in the right direction.  As long as none of your values have semicolons in them, his code should get it done for you. Smiley
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print