Hot Topic (More than 10 Replies) @StringArrayElementList sorting (Read 6534 times)
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
@StringArrayElementList sorting
Aug 3rd, 2006 at 5:18am
Print Post Print Post  
I cannot understand how the @StringArrayElementList sorts the elements by their order on the form.  I am running this and the elements are coming up in a different order.  At first I thought they were in order, then I moved some elements on the form but the output stayed the same.  Then I changed the Navigation sequence hoping that would have an effect but still coming out in an order that does not match the layout top to bottom, left to right.  The output is consistent, but not in proper order.
Here is a list of the Y positions in order of element list:
736,2,7,2,38,39,116,404,461,44,43,44,71,72,93 etc.

You can see that the very first item is wrong.  It was originally at the top of the form, but moved to bottom later.  The "4xx" items were also moved down to bottom of form.  Are these perhaps coming out in the order they were added?  How can they be sorted to come out sorted in Y/X order?

In Programming Guide, page 119, it uses this function and says that it returns a list of the elements in the order they are on the form.  This example is in the section for @NumberOfElements(), bust uses the function as part its example.

WriteLn("There are " + n + " elements on this " + @Layout + " form.")
ForceRedraw()
Loiter(2000)
WriteLn("")
WriteLn("And here they are in the order they appear on the form:")
WriteLn("")
For i = 1 to n
vElements += @AccessStringArray(@StringArrayElementList(), i) +
@NewLine()
Next
WriteLn(vElements)





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


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: @StringArrayElementList sorting
Reply #1 - Aug 3rd, 2006 at 1:41pm
Print Post Print Post  
Does this form have Tabs, Subforms, or Radio Buttons on it?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: @StringArrayElementList sorting
Reply #2 - Aug 3rd, 2006 at 4:51pm
Print Post Print Post  
Yes, there are 5 tab pages. Only one group of radio buttons.
And 0 subforms.

The very first item, Y=436 is a Static text label, that was moved from a tab to the canvas bossom.  Here is a quick list in order returned
with Y values
736 - Static Text on canvas
2 - Static Push Button on canvas
7 - Text Box on canvas
2 - Check box next to previous textbox
2 - Another check box, next to previous on
38  - first tab page
39 - box on tab
Wait, now I think I see a trend.  It looks like all Static text element types are being done befor data entry elements.  All boxes and Static text labels are first, then followed by Text fields, combo boxes, and radio buttons, etc. in correct order.  Then when getting to next Tab all the boxes and Static Text labesl are first and then the normal data entry fields. ?  Am I wrong to think these were supposed to be in order of layout?  Or does it do both? does it do static elements in order and then data entry elements in order?

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


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: @StringArrayElementList sorting
Reply #3 - Aug 3rd, 2006 at 5:17pm
Print Post Print Post  
The @NumberOfElements() sample you refer to assumes a very simple form. The documentation for @StringArrayElementList() itself does not specify any particular order. The list is returned in internal "widget list" order.  For a simple form, this will likely match the order they appear on the Form. However, the order of this list is affected by a number of things, including editing navigation order and the presence of container or parent elements (like tab pages). The list is not in order by any particular attribute of the elements themselves. The purpose of this function is simply to return a list of the element names so they can be accessed for other purposes.

If your particular purpose needs the elements sorted by X and Y position, you can use @XPos() and @YPos to return those properties and reorder the list based on them.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: @StringArrayElementList sorting
Reply #4 - Aug 3rd, 2006 at 5:58pm
Print Post Print Post  
Thank you for making that clear.  Will the sort work correctly with Y and X as numbers or will they sort as text?  Does that mean that maybe all might need leading zeroes for correct sort?  Do I need to make something like YYYY-XXXX-ElementName to sort, then drop off the YYYY-XXXX-prefix?  Can you give a sample of how to get the element list, assgn the Y/X positions, and end up with a new list of Element Names sorted by Y and then by X?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @StringArrayElementList sorting
Reply #5 - Aug 3rd, 2006 at 7:03pm
Print Post Print Post  
You could use your way, by making a concatenated string of the x and y positions. You could also do a numeric comparison by check the y and if there is a tie, then checking the x. Or if you want you can use the following formula: n = (y * form_width) + x top and compare a single number.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: @StringArrayElementList sorting
Reply #6 - Aug 3rd, 2006 at 9:22pm
Print Post Print Post  
I tried to use your formula but it is not workiing for me.  What is happening now is that I am seeing all the fields from all the tabs mixed together.  This is worse than what I had at first.  Does anyone else have a way to do sort the elements in order by screen layouts and tabs?
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: @StringArrayElementList sorting
Reply #7 - Aug 3rd, 2006 at 9:31pm
Print Post Print Post  
obfusc88 wrote on Aug 3rd, 2006 at 9:22pm:
I tried to use your formula but it is not workiing for me.  What is happening now is that I am seeing all the fields from all the tabs mixed together.  This is worse than what I had at first.  Does anyone else have a way to do sort the elements in order by screen layouts and tabs?


I wrote an article for Inside Sesame a short while ago that provides code for unrolling tabs for printing a form. You will need to do something similar to what it does.  It even unrolls tabs on tabs. Note that this is not bulletproof. The piece you won't know is where the very last tab ends, so elements parented to the main form that appear after the tab group may not show up where you want them to in your list.
  

- Hammer
The plural of anecdote is not data.
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: @StringArrayElementList sorting
Reply #8 - Aug 3rd, 2006 at 10:02pm
Print Post Print Post  
New Tab Pages have an almost unique Element Type, Static Group. 
Using that value, then this may do the trick for you:

Code
Select All
var vElementName as string
var vElementList as string
var vListCount as Int
var vLoop as Int
var vThisElement as String

var vSortIndex as Int			//Sorting Index = (800 * YPos) + XPos
var vIndexedElements as String		//Unsorted Indexed elements
var vSortedPageElements as String	//Sorted Indexed elements

// 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 + "/Y:" + @YPos(ThisElement) + "/X:" + @XPos(ThisElement) +    ";"

     // 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
	     WriteLn(vSortedPageElements)					//Review list of Sorted elements
	     }								     //Can Copy/Paste to review
	vLoop += 1
     }								    //End of While Loop

 



Logic of the programming:
1.  The TabPage has an Element Type = Static Group, or code 1016. 
2.  Go thru the list of elements and make a sorting Index and append each element to a string array (vIndexedElements).
3.  When you get to an element type = 1016, then this is the begining of a new tab.
4.  So take the existing list, sort it, and append the results to the Sorted elements (vSortedPageElements).
5.  Now clear out the current list (vIndexedElements) so that you can start again on the next Tab Page.
6.  Repeat through all elements (vListCount)

Is this a Sensible Solution?

« Last Edit: Aug 4th, 2006 at 1:12am by Bob_Hansen »  



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: @StringArrayElementList sorting
Reply #9 - Aug 4th, 2006 at 9:10pm
Print Post Print Post  
Thank yo to evryone for the help.  I don't get Sesame Insider so I could not look at article from Hammer.  I tried the stuff form bob_hansen and it looks like it is much vetter than I starte with. I think that it is now working for me.  It shows all of the things in a better order but I need to clean that up now.  But I did not need the information at the end so I removed that.  How does the index thing work?  This line worked to help sort -- "vSortIndex = (800 * @YPos(ThisElement) ) + @XPos(ThisElement) " but how did you make this number ?  And how do get rid of the the number at the front?

  
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: @StringArrayElementList sorting
Reply #10 - Aug 4th, 2006 at 10:18pm
Print Post Print Post  
Re the formula for this line:
Code
Select All
"vSortIndex = (800 * @YPos(ThisElement) ) + @XPos(ThisElement)" 



That was created thanks to the formula that Mark left in earlier message.
Quote:
you can use the following formula: n = (y * form_width) + x top


His formula used the form width.  I just decided to use 800 as a constant that was high enough to cover a good range of form widths.  It could be any number that you want.

Re the extra information, I think that I might be able to come up with a function to do this.  No promises, but the earlier code I provided does a lot of the work now, needs some snhancements .......

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
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: @StringArrayElementList sorting
Reply #11 - Aug 5th, 2006 at 1:50am
Print Post Print Post  
Hello obfusc88

I have modified the code from above and created a generic function that returns a Sorted Element List that makes resorts when it comes to a new Tab Page.

The function is named fnGetSortedElementList() and can be found here:
http://www.lantica.com/Forum3/cgi-bin/yabb2/YaBB.pl?num=1154742258/0#0

This is much better than the code I left you with that included a bunch of unwanted data.
Thanks for your patience.

  



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: @StringArrayElementList sorting
Reply #12 - Aug 5th, 2006 at 1:27pm
Print Post Print Post  
OK, that sounds good because I was having trouble to remove extra numbers at the front from WriteLn.  I will try to ss how that works.
  
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: @StringArrayElementList sorting
Reply #13 - Aug 5th, 2006 at 8:24pm
Print Post Print Post  
Just thought I would mention that I don't get Sesame Insider either.  Not sure where to get it.   Huh 
I know, it was just a typo, just kiddiing you.

But I highly recommend getting Inside Sesame.  Every issue is packed with great usable information.  Even if you don't need the specific application of the month, you will still get many examples of how to use Sbasic and its Sesame functions.  And you will be able to read Erika's articles also.

  



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