Hot Topic (More than 10 Replies) Can retrieve criteria be counted? (Read 994 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Can retrieve criteria be counted?
Sep 18th, 2007 at 7:00pm
Print Post Print Post  
Some of my Invoice reports, such as a billing statement, are meant to be run against a single customer's records.  If it is run when the retrieve spec is blank or specifies multiple customers, the results are meaningless; mixed data.

Is there a way to have Sesame "count" the number of criteria used and MSGBOX the user if their selection is invalid?  I'm thinking two things might happen: either the field is empty in the retrieve spec, or it contains one or more semicolons.  Can Sesame look at that?
  

**
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 retrieve criteria be counted?
Reply #1 - Sep 18th, 2007 at 7:27pm
Print Post Print Post  
Hello Scott,

The following will write out what retrieve criteria was entered at the retrieve spec.

Code
Select All
#Include "sbasic_include.sbas"

Var vlist as String

vList = @StringArrayAttributes(@StringArrayElementList(), ATTR_ID_TEMPORARY_VALUE)
Writeln(vList) 



You will need to run this from an event on the form itself. Such as in a command button that runs the report.

To specify just one element or a select handful of elements you would replace @StringArrayElementList() with the name of the element, or element names seperated with semi-colons, in quotes.

You will need to parse out the information from vList as it will return a StringArray of the retrieve criteria.

-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 retrieve criteria be counted?
Reply #2 - Sep 18th, 2007 at 7:35pm
Print Post Print Post  
Thanks Ray, I'll experiment with it.
  

**
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 retrieve criteria be counted?
Reply #3 - Sep 18th, 2007 at 7:42pm
Print Post Print Post  
One thing you are probably going to want to do is call SetStringArraySeparator() to change the Separator to something other than a semi-colon so that you can see if you have semi-colons in the retrieve criteria.

-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 retrieve criteria be counted?
Reply #4 - Sep 18th, 2007 at 8:09pm
Print Post Print Post  
This is what I have so far.  The first test works nicely if the user is not in Update Mode.  However, the second test pops up a MSGBOX no matter what is in the Bill_To_Code for criteria.  It should only pop up if the vList is empty (no criteria selected at all).  But vList happily displays the values in the slate, and then I get the message.  Clearly I'm missing a step in the logic somewhere.
Code
Select All
Var vPrintTheReport as string
Var vlist as String
Var vNewRetrieveSpec as Int


IF NOT @Mode() = 1
THEN
	{
	@MSGBOX("Reports can only be run in Update mode", "Please switch to Update and", "select the records you wish to run the report on.")
	vNewRetrieveSpec = @SelectTreeItem("Search Update Menu!Search (F7)")
	}
ELSE
{
// vList = @StringArrayAttributes(@StringArrayElementList(), ATTR_ID_TEMPORARY_VALUE)
vList = @StringArrayAttributes("Bill_To_Code", ATTR_ID_TEMPORARY_VALUE)

Writeln(vList)

IF @IsBlank(vList)
THEN
	{
	@MSGBOX("This report must be run against a single Customer's records.",
		"Please return to the retrieve spec and select a specific customer.",
		"")
		vNewRetrieveSpec = @SelectTreeItem("Search Update Menu!Search (F7)")
	}
ELSE
	{
	vPrintTheReport = @PrintAReport(". Customer History", REPORT_MODE_HTML_PREVIEW, PRINT_ORIENTATION_PORTRAIT, 0, -1, -1, -1, -1, -1, -1)
	}
} 

  

**
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 retrieve criteria be counted?
Reply #5 - Sep 18th, 2007 at 8:17pm
Print Post Print Post  
@IsBlank() only works with elements. For checking String Variables you will want to use = ""

-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 retrieve criteria be counted?
Reply #6 - Sep 18th, 2007 at 8:23pm
Print Post Print Post  
Ah, OK.  Very nice, works well with that.  Step one is done, checking for blank retrieves.  Now, onto step 2, for multiple codes.
  

**
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 retrieve criteria be counted?
Reply #7 - Sep 18th, 2007 at 8:39pm
Print Post Print Post  
Where would I put the SetStringArraySeparator() command?  I'm trying it here:
Code
Select All
SetStringArraySeparator("^")
vList = @StringArrayAttributes("Bill_To_Code", ATTR_ID_TEMPORARY_VALUE)

Writeln(vList)

IF (vList = "" OR @INSTR(vList, "^") > 0) 


But it's not working.
  

**
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 retrieve criteria be counted?
Reply #8 - Sep 18th, 2007 at 8:52pm
Print Post Print Post  
This seems to be working:
Code
Select All
// Prints the expanded Monthly Billing report

Var vPrintTheReport as string
Var vlist as String
Var vNewRetrieveSpec as Int

IF NOT @Mode() = 1
THEN
	{
	@MSGBOX("Reports can only be run in Update mode",
		"Please switch to Search/Update and retrieve the records",
		"you wish to run the report on before running the report.")
	}
ELSE
{
// vList = @StringArrayAttributes(@StringArrayElementList(), ATTR_ID_TEMPORARY_VALUE)

vList = @StringArrayAttributes("Bill_To_Code", ATTR_ID_TEMPORARY_VALUE)


Writeln(vList)

// IF (vList = "" OR @INSTR(vList, "^") > 0)
IF (vList = "" OR @INSTR(vList, ";") > 0)
THEN
	{
	@MSGBOX("This report must be run against a single Customer's records.",
		"Please return to the retrieve spec and select a specific Code.",
		"")
		vNewRetrieveSpec = @SelectTreeItem("Search Update Menu!Search (F7)")
	}
ELSE
	{
	vPrintTheReport = @PrintAReport(". Customer History", REPORT_MODE_HTML_PREVIEW, PRINT_ORIENTATION_PORTRAIT, 0, -1, -1, -1, -1, -1, -1)
	}
} 


Thanks for your help, Ray.  Please point out if I've screwed something up or if there's a more delicate way of doing this.  If not, I'll roll it into all my "Print Report" buttons tomorrow.
  

**
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 retrieve criteria be counted?
Reply #9 - Sep 18th, 2007 at 8:56pm
Print Post Print Post  
That's the right place for it, but since you are not getting the Temporary value of several elements it is not being used. If you were getting the values of Bill_To_Code and let's say Company_Name the results would come back as

Bill_To_Code^Company_Name
or(with fake data)
a..;b..^/Ray..

This way you can distigush the ; entered as a retrieve criteria from the ; that @StringArrayAttributes() would have inserted.

If you are only checking one element then you don't need to use it.

Also as a tip, whenever you use SetStringArraySeparator() be sure to use RestoreStringArraySeparator(). It will save you some hair when things start acting odd because a ; is no longer the correct separator.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
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 retrieve criteria be counted?
Reply #10 - Sep 18th, 2007 at 9:01pm
Print Post Print Post  
Hello Scott

If it were me I would change the logic of
Code
Select All
IF (vList = "" OR @INSTR(vList, ";") > 0) 


To
Code
Select All
IF ((vList = "") OR (@INSTR(vList, ";") > 0)) 



It just has some added parentheses to make the logic a bit clearer(to me atleast) and group together each section. Not really important in this case but it's a good habit to get into in case you ever write long If statements that combine AND's and OR's.


-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 retrieve criteria be counted?
Reply #11 - Sep 18th, 2007 at 9:01pm
Print Post Print Post  
Thanks Ray, you've taught me a lot today!
  

**
Captain Infinity
Back to top
IP Logged