Normal Topic Get Sorted Element List function (Read 7343 times)
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Get Sorted Element List function
Aug 5th, 2006 at 1:44am
Print Post Print Post  
I recently responded to a forum question ( http://www.lantica.com/Forum3/cgi-bin/yabb2/YaBB.pl?num=1154582330) about sorted elements lists.  After working on that, i was motivated to enhance my quick and dirty response. 

I have made some major changes but ended up with this generic function that can be called from anywhere. When the function is called it returns a semicolon delimited string of all the elements on the form, sorted by the Y position and then the X position.  Once you have the list you can do anything you want with it, like looking for/changing certain values, properties, etc.  I have included this function in my copy of Data Dictionary.

Code
Select All
Function fnGetSortedElementList() as String

var vElementName as string

var vThisElement as String
var vElementList as string
var vListCount as Int
var vLoop as Int
var vSortIndex as Int				//Sorting Index = (800 * YPos) + XPos
var vIndexedElements as String			//Unsorted Indexed elements
var vSortedPageElements as String		//Sorted Indexed elements
var vIndexed as String
var vSortedElements as String


// List all elements on the form
vElementList = @StringArrayElementList()

// Count elements in the list
vListCount = @CountStringArray(vElementList)

// Loop through all the elements
vLoop = 1
While(vLoop <= vListCount) {

	// Extract each element in the list, Set the "ThisElement" pointer
	vElementName = @AccessStringArray(vElementList, vLoop)
	SetThisElement(vElementName)

	// Make Sort Index for elements using Y/Z positions
	vSortIndex = (800 * @YPos(ThisElement) ) + @XPos(ThisElement)
	vIndexedElements += vSortIndex + "~" +  vElementName + ";"

	// Sort elements by Y/Z positions on each Tab Page / FieldType = "1016/Static Group"
	If @ElementType(ThisELement) = "1016" Then {
		vIndexedElements = @SortStringArray(vIndexedElements,1)	//Sort current element list by numbers
		vSortedPageElements += ";" + vIndexedElements			//Append to Sorted list
		vIndexedElements = ""									//Clear for next page of elements
		}													//Can Copy/Paste to review
	vLoop += 1
	}								//End of While Loop

vSortedPageElements += ";" + vIndexedElements				//Append to Sorted list
VSortedPageElements = @Replace(vSortedPageElements,";;",";")

//Remove Index from Element Names
// Count elements in the list
vListCount = @CountStringArray(vSortedPageElements)

vLoop = 1
While(VLoop <= vListCount) {

	// Extract each element in the list
	vElementName = @AccessStringArray(vSortedPageElements, vLoop)
	vIndexed=@Right(vElementName,@Len(vElementName)-@Instr(vElementName,"~") )
	vSortedElements += vIndexed + ";"
	vLoop += 1
	}

vSortedElements = @DeleteStringArray(vSortedElements,1)		   //Remove leading semicolon

Return vSortedElements				//Value to be returned to Function Call

End Function 



Usage:
Code
Select All
var vSortedElements as String
vSortedElements = fnGetSortedElementList() 


------------------------------------------------------------
There may some instances where order may not be totally correct, but this currently works with multiple large Tab Pages on a form and almost 200 elements.  It was tested out with five TabPages, that were almost full screen.  The elements come out in the order that they show on the Tab Pages, in page sequence. 

Thanks to obfusc88 for the initial problem.
And thanks to Mark (Cow) for his formula to create an index number.


I would appreciate any feedback on its usage or any problems that are encountered.
  



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


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Get Sorted Element List function
Reply #1 - Aug 5th, 2006 at 1:32pm
Print Post Print Post  
This looks like it might be confusing to me.  What is your Data Dictionary that you used?  Do I need to have that to make this work?  I might not be able to try this until next week because of vacation time, but I hope that this will work out.
  
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: Get Sorted Element List function
Reply #2 - Aug 5th, 2006 at 8:32pm
Print Post Print Post  
It should not be too confusing to use.  The syntax example is easy enough. 
But the undocumented logic may be confusing.  I will provide an explanation to the logic soon.

Data Dictionary is a Sesame utility that can be purchased from Inside Sesame (have you subscribed yet?  If not, do it!). 

You do not need Data Dictionary to use this function, but I have substituted this function for one that is currently used in that utility.

And enjoy your vacation!!
  



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: Get Sorted Element List function
Reply #3 - Aug 9th, 2006 at 6:26pm
Print Post Print Post  
Bob;  Is there a way to have the Data Dictionary program show the "Initial Values" of form elements?
  

**
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: Get Sorted Element List function
Reply #4 - Aug 9th, 2006 at 9:08pm
Print Post Print Post  
NO, there are a number of element properties that cannot be picked up. 

This is not a shortcoming of Data Dictionary, it is the lack of commands available in Sesame's SBasic. 

You cannot get colors for Text/Background/Fill areas. 
You cannot get Initial Values or Help or Tooltips, Box Types, etc.
  



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


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Get Sorted Element List function
Reply #5 - May 16th, 2007 at 8:30pm
Print Post Print Post  
I use the following code to get the information I need on the form. I believe this could be a substitute for Data Dictionary.

Place a Command button on the form and following code goes on Element Entry Event

Code
Select All
var vList as String
var vLine as String
var n as Int
var vDelimit as String = ";"
var vTotal as Int
var vElement as String
var i as Int
var vName as String
var vCount as Int


WriteLn ( "Application Name is " + @application)
WriteLn ( "Database Name is " + @Database)
WriteLn ( "Layout (Form) Name is " + @layout)
vTotal = @NumberofElements( )
WriteLn ("There are " + vTotal + " Number of Elements in " + @layout + " layout")

Vlist = @stringArrayElementList( )
WriteLn (VList)

WriteLn ("ElementName		  " + "Element BoundTo	 "   + "Label		   " + "BoundToType" )
WriteLn (@text (80, "="))


VLine = ""

/*

//WriteLn (vList)
	  For i = 1 to vTotal


		    vElement = Split (vList, vDelimit)
		    vLine = vElement + @text (24 - @len (vElement), " ") +
		    @ElementBoundTo (@(vElement)) + @text (20 - @len (@ElementBoundTo (@(vElement))), " ") +
		    @Label (@(vElement)) +  @text ( 20 - @Len (@Label (@(vElement))), " ") +
		    @ElementBoundToType(@(vElement))
		    WriteLn (vLine)
			  //WriteLn (vElement)


	  Next
*/

vList = @stringArrayElementList( )
vCount = @CountStringArray (vList)
n =1
While n <= vCount
	{
		vName = @AccessStringArray (vList, n)
		vLine = ""
		//vElement = Split (vList, vDelimit)
		vLine = vName
		SetThisElement ( vName)
		vLine = vLine + @text (24 - @len (vName), " ") +
		    @ElementBoundTo (ThisElement) + @text (20 - @len (@ElementBoundTo (ThisElement)), " ") +
		    @Label (ThisElement) +  @text ( 20 - @Len (@Label (ThisElement)), " ") +
		    @ElementBoundToType(ThisElement)
		    WriteLn (vLine)
		n = n + 1


	}
UnsetThisElement ( )
 



I am not sure how does this compare with Data Dictionary but serves the purpose for me. I have it on practically all of my forms.

This displays the information in the WriteLn windows. If you need to have printed sheet, copy everything on the clipboard and paste it in Word document, change the font to Currier for proper placing and print it out using Landscape Page format. Works for me!!!

Bharat

  
Back to top
 
IP Logged