Normal Topic Saving Retrieve Specs via programming (Read 1284 times)
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Saving Retrieve Specs via programming
Nov 9th, 2006 at 2:31am
Print Post Print Post  
Besides using a macro, is there a way to save a retrieve spec through programming?

If not, @SaveRetrieveSpec() would be a great addition to 2.0. Wink
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
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: Saving Retrieve Specs via programming
Reply #1 - Nov 9th, 2006 at 5:44am
Print Post Print Post  
Good idea Carl

Look for an email from me re one of my tolls that I provided for you.  Might be a possibility there.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
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: Saving Retrieve Specs via programming
Reply #2 - Nov 9th, 2006 at 3:44pm
Print Post Print Post  
Hello Carl,

I am not sure of a way in programming to save an Actual Retrieve spec that shows up in the Spec Manager in 1.1.4, But I did come up with a way to save the values at the Retrieve spec so you can re-use them.

Put two buttons on your form. One to Save the Spec and one to Load the spec. Then comes the following program.

Code
Select All
** PROGRAMMING SECTION: [ GLOBAL CODE ] [] **
Stat gsElementList as String
Stat gsButtonList as String

Subroutine GetSetRetrieve(vWhich as String, Var vValues as String)
Var vLoop as Int
Var vCnt as Int
Var vName as String
Var vPart as String

	vLoop = 1
	If vWhich = "GET" Then
	{
		vValues = ""
		vCnt = @CountStringArray(gsElementList)
		While vLoop <= vCnt
		{
			vName = @AccessStringArray(gsElementList, vLoop)
			SetThisElement(vName)
			If ((@ElementType(ThisElement) < 1009) And (@IsBlank(ThisElement) = 0)) Then
			{
				vValues = vValues + @ElementName(ThisElement) + "=" + ThisElement + "^"
			}
			UnSetThisElement()
			vLoop = vLoop + 1
		}
	}
	Else If vWhich = "SET" Then
	{
		SetStringArraySeparator("^")
		vCnt = @CountStringArray(vValues)
		While vLoop <= vCnt
		{
			vPart = @AccessStringArray(vValues, vLoop)
			If vPart <> "" Then
			{
				vName = Split(vPart, "=")
				SetThisElement(vName)
				ThisElement = vPart
				UnSetThisElement()
			}
			vLoop = vLoop + 1
		}
		RestoreStringArraySeparator()
	}

End Subroutine

Subroutine SetVisibility(vElements as String, State as Int)
Var vLoop as Int
Var vCnt as Int
Var vName as String

	vLoop = 1
	vCnt = @CountStringArray(vElements)

	While vLoop <= vCnt
	{
		vName = @AccessStringArray(vElements, vLoop)
		SetThisElement(vName)
		Visibility(ThisElement, State)
		UnSetThisElement()
		vLoop = vLoop + 1
	}

End Subroutine

gsElementList = @StringArrayElementList()
gsButtonList = "Load;Save"



** PROGRAMMING SECTION: [Main Form] [On Form Entry] **
	SetVisibility(gsButtonList, 0)



** PROGRAMMING SECTION: [Main Form] [On Retrieve Spec Open] **
	SetVisibility(gsButtonList, 1)



** PROGRAMMING SECTION: [Load] [On Element Entry] **
Var vName as String
Var vRetValues as String
Var vSpecs as String
Var vSuccess as Int

vSpecs = @GlobalValue("CustomRetrieveSpecs")
PopupSelectPosition(4, @XPos(ThisElement) + 60, @YPos(ThisElement) + 20)
vName = @PopupMenu(vSpecs, "Choose Spec to Load")

If vName <> "" Then
{
	vSuccess = @SelectTreeItem("Search Menu!Clear Form (F3)")
	vRetValues = @GlobalValue(vName)
	GetSetRetrieve("SET", vRetValues)
	ForceRedraw()
}



** PROGRAMMING SECTION: [Save] [On Element Entry] **
Var vName as String
Var vRetValues as String
Var vSave as Int
Var vSpecs as String
Var vAddToList as Int

vName = @PromptForUserInput("Please Enter a Name for the Custom Spec", "")
vSave = 1
vAddToList = 1

If vName <> "" Then
{
	If @Len(@GlobalValue(vName)) > 0 Then
	{
		vSave = 0
		If @ASkUser("Warning", "A Custom Retrieve spec with the name of " + vName + " already exists!", "Do you want to Overwrite it") Then
		{
			vSave = 1
			vAddToList = 0
		}
	}
	If vSave = 1 Then
	{
		GetSetRetrieve("GET", vRetValues)
		GlobalValue(vName, vRetValues)
		If vAddToList = 1 Then
		{
			vSpecs = @GlobalValue("CustomRetrieveSpecs")
			vSpecs = @AppendStringArray(vSpecs, vName)
			GlobalValue("CustomRetrieveSpecs", vSpecs)
		}
	}
} 



It may be a little rough around the edges as I just wrote it this morning but it should give you an idea of how it could be done. And the only changes anyone should have to make is to change the last line in global code that reads
Code
Select All
gsButtonList = "Load;Save" 

to be the names of the buttons that they only want visible at the retrieve spec.

I have all this in a sample app if anyone would like to see it. Just send an E-mail to support@lantica.com and ask for SaveCustomRetrieves.db

If you really wanted to you could also add a button to delete a custom spec, or even set it as the default spec.

-Ray

-Edit-
Had to add a ForceRedraw() to the Load portion of the code to cause the form to redraw.
« Last Edit: Nov 9th, 2006 at 10:09pm by Ray the Reaper »  

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: Saving Retrieve Specs via programming
Reply #3 - Nov 9th, 2006 at 4:51pm
Print Post Print Post  
Very creative Ray, the power of Sesame is showing off again!
Smiley   Smiley
Request has been submitted.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
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: Saving Retrieve Specs via programming
Reply #4 - Nov 9th, 2006 at 10:07pm
Print Post Print Post  
Hello Bob,

Files have been sent your way. Let me know if you have any problems with them.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Saving Retrieve Specs via programming
Reply #5 - Nov 10th, 2006 at 12:43am
Print Post Print Post  
Ray,

Very nice! That's exactly what I needed.

I had considered using GlobalValues, and knew that it would take a bit of programming (and time to tweak it). So, that's what led me to ask if there might be some function that I had somehow overlooked. I never expected you to create it for me, though. Shocked

Thank you! You just saved me some work. Smiley
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Saving Retrieve Specs via programming
Reply #6 - Nov 10th, 2006 at 12:56am
Print Post Print Post  
Ray,

I have question regarding your choice of programming technique.

You used:

Code
Select All
SetThisElement(vName)
ThisElement = vPart
UnSetThisElement() 



Rather than simply:

Code
Select All
@(vName) = vPart 



Is there a reason I should be using the first example instead of the second? I have been using the second style in some of my applications, and have not noticed any problems. The only reason I like it is because it saves a couple of lines of code.
  


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



Posts: 2530
Joined: Nov 22nd, 2002
Re: Saving Retrieve Specs via programming
Reply #7 - Nov 10th, 2006 at 1:25am
Print Post Print Post  
I can't really answer for Ray, but I can say that the @(...) construct has to re-resolve the element reference everytime it is used, and that since the resulting reference cannot be set to a variable, the reference cannot be kept. Once ThisElement is set, whether by defaulting to the current element (that running code), or by using SetThisElement, it does not need to be set again each time it is used. If you have a large form with many elements, this can save a considerable amount of time if you are going to use the element reference more than once.

Basically, using @(...) is the same as both the call to SetThisElement and the actual single use of ThisElement. the SetThisElement call runs through all of the elements available to the code until it finds the one that matches the passed name. @(...) does the same. But once, ThisElement is set, it can used over and over again without having to loop through the elements on the form. @(...) must find a matching element everytime it is called.
  

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



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Saving Retrieve Specs via programming
Reply #8 - Nov 10th, 2006 at 4:37am
Print Post Print Post  
Mark,

Thank you for clarifying the differences between the two methods. It makes very good sense, now.

My intention was to make things more efficient by having fewer lines of code, so that the compile time when opening the form for the first time per session, would be shorter. But apparently, I was making it less efficient when actually executing.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
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: Saving Retrieve Specs via programming
Reply #9 - Nov 10th, 2006 at 2:45pm
Print Post Print Post  
Hello Carl,
Quote:
Ray,

I have question regarding your choice of programming technique.

You used:

Code
Select All
SetThisElement(vName)
ThisElement = vPart
UnSetThisElement() 



Rather than simply:

Code
Select All
@(vName) = vPart 



Is there a reason I should be using the first example instead of the second? I have been using the second style in some of my applications, and have not noticed any problems. The only reason I like it is because it saves a couple of lines of code.


I used ThisElement in case something else needed to be done as well, such as set the background color of the element so the user can easily see what elements had been filled in with values.

Quote:
Thank you! You just saved me some work. Smiley


You're welcome.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged