We are often informed that you need to do a particular operation on a whol;e lot of layout elements, but because there are so many, you do not want to have to type in all of their names. Here is a little snippet of code that allows you to operate on a whole set of of LEs, filtering which ones to operate on by a "range" and by the way that they are named. This function allows you to set a range from one field to another in the order in which they appear (or tab order if it has been edited), then within that range filter via a search/restriction spec that matches against the LE name.
Using Customers.db as an example:
str = RangeIt("Company", "State", "") // will return all the LEs between Company and State (including Company and State)
str = RangeIt("Company", "State", "A..") // will return all the LEs between Company and State that begin with the letter "A" (including Company and State)
str = RangeIt("", "", "A..") // wiill return all the LEs on the form that start with the letter "A"
str = RangeIt("Company", "", "") // will return all the LEs on the form that are after Company (including Company)
str = RangeIt("", "State", "") // will return all the LEs on the form that are before State (including State)
The basic calling syntax for this function is:
RangeIt(start_LE as string, stop_LE as string, match as string) as string
** PROGRAMMING SECTION: [ GLOBAL CODE ] [] **
function RangeIt(start_name as string, stop_name as string, match as string) as string
// Declare variables
var str as string
var result_list as string
var name as string
var cnt as int
var loop as int
var start_i as int
var stop_i as int
// Initialize the list to all the LEs
str = @StringArrayElementList()
// Count the total set of all LEs
cnt = @CountStringArray(str)
// Initialize variables
result_list = ""
start_i = -1
stop_i = -1
// Ste defaults for variables
if(start_name = "")
{
start_i = 1
}
if(match = "")
{
match = ".."
}
// Loop through all the LEs
for loop = 1 to cnt
// Get the name of a LE in the list
name = @AccessStringArray(str, loop)
// See if we up to the first name yet
if(name = start_name)
{
start_i = loop;
}
// If we are up to the first name but not yet at the last name
if((start_i > -1) and (stop_i = -1))
{
// Does this LE name match the search spec
if(@SearchStringArray(name, match) <> "")
{
// Add the name to the results list
result_list = result_list + name
if(name = stop_name)
{
stop_i = loop
}
else
{
// Tack on a semi-colon if not done
result_list = result_list + ";"
}
}
}
next
return(result_list)
end function
// To call the function above - use code that looks something like this
var str as string
var name as string
var loop as int
var cnt as int
// Check for LEs between Company and State for those starting with A
str = RangeIt("Company", "State", "A..")
// Count how many we got
cnt = @CountStringArray(str)
for loop = 1 to cnt
// Get the name
name = @AccessStringArray(str, loop)
// Set this element to that LE
SetThisElement(name)
// Set the value - replace this with your operation
ThisElement = "This is the value I want to set"
// Return this element to the default LE
UnSetThisElement()
next