Page Index Toggle Pages: 1 [2]  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) Can this code be shortened? (Read 2417 times)
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 #15 - Jun 23rd, 2006 at 7:48pm
Print Post Print Post  
I've been using the code Mark provided a few posts up, in several places in my databases:
Code
Select All
if(@instr("TQAB", Billing_Code) > 0)
{
  // Take Action
} 



But I'm having trouble with the test in other fields, and I think the syntax is off.  Page 52 of the Q&A 5.0 Application Programming Tools Manual shows the syntax as
Code
Select All
@INSTR(x,y)  //Returns the position (an integer) of the first occurrence of the string y in the text x. 


And gives the example #10 = @INSTR(#20,"blue")

Following this example, shouldn't the solution above read
Code
Select All
if(@instr(Billing_Code,"TQAB") > 0)
{
  // Take Action
} 



?

In another spot in my databse the code
Code
Select All
>#1875:
IF (#4099="" AND (@INSTR(#1875,"T") > 0))
    THEN
    {
     // action
     } 


seems to be working as I want it to.  Funny thing is, the original "TQAB" test seemed to work, too.  I'm going to have to double-check it.

So this is puzzling.  Beyond the question of which is correct for Q&A, which is correct for Sesame?
  

**
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 #16 - Jun 23rd, 2006 at 8:11pm
Print Post Print Post  
OK, I double checked.  This:
Code
Select All
if(@instr("TQAB", Billing_Code) > 0)
{
  // Take Action
}  


does not work correctly.

However, this:
Code
Select All
if(@instr(Billing_Code,"TQAB") > 0)
{
  // Take Action
}  


does work...but only for the exact value TQAB.

I'll need to study recent coding posts and try to figure out how they work, to test the field for a T or a Q or an A or a B (but not TQAB).

My head hurts.  Need coffee.  And a nap.
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Can this code be shortened?
Reply #17 - Jun 23rd, 2006 at 8:23pm
Print Post Print Post  
Hello Scott,

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



Will work as long as Billing_Code is only one character long. Lets say that Billing Code is T. The code says search the string "TQAB" for the the string 'T'. Found it. It is at position 1. Okay is 1 greater than 0. Yes it is so lets run the code in my curly braces.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
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 #18 - Jun 23rd, 2006 at 8:34pm
Print Post Print Post  
OK, tested that and you're right.   Hmmm.  So are both syntax forms correct, or am I just misunderstanding it?
  

**
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 #19 - Jun 23rd, 2006 at 8:39pm
Print Post Print Post  
Ah, I think I get it now.  In one case, the contents of BILLING_CODE is tested to see if it is contained in the string "TQAB".  In the second case, the string "T" is tested to see if it is contained in field #1875.

So they're both right.  YAY!  Clearly I need more practice with @INSTR()
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Can this code be shortened?
Reply #20 - Jun 23rd, 2006 at 8:41pm
Print Post Print Post  
Both are syntactically correct. The one{@instr("TQAB", Billing_Code)} says to search the string "TQAB" for the value in Billing_Code. The other{@instr(Billing_Code, "TQAB")} says to search the value in Billing_Code for the string "TQAB".

-Ray

-edit-

Yup you got it.
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
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 #21 - Jun 23rd, 2006 at 8:45pm
Print Post Print Post  
From the Programming Guide, page 35:
@INSTR(x,y) Returns the position of the first occurrence of y in x.
X is where you are looking st to find Y
Y is what you are looking for inside X.

Mark's suggestion here was correct: Quote:
// 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


Carl's suggestion to use leading and trailing semicolons is also correct.

So, you are looking in MyField to see if the value in Billling_Code is there.
So, X = MyField, and Y = Billing_Code surrounded with semicolons. =
";3500;6472;3444;3481;3751;3915;2897;3939;4029;2318;3907;2075;2834;4883;"

So the following code should Take Action if the Billing Code number is in the string MyField which was defined earlier, with leading and trailing semicolons, with semicolon separators, no spaces.
Code
Select All
IF (@INSTR(MyField, ";" + Billing_Code + ";") > 0) THEN {
	// Take Action
	WriteLn("Take Action")
	}  



And what is the result?

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send Topic Send Topic Print Print