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.
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:
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.