Normal Topic Operating on a range of form elements (Read 5297 times)
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Operating on a range of form elements
Sep 10th, 2004 at 2:31pm
Print Post Print Post  
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

Code
Select All
** 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
 


Code
Select All
// 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
 

« Last Edit: Sep 10th, 2004 at 5:45pm by The Cow »  

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



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: Operating on a range of form elements
Reply #1 - Sep 10th, 2004 at 5:24pm
Print Post Print Post  
Quote:
str = RangeIt("", "State", "") // will return all the LEs on the form that are after State

The basic calling syntax for this function is:

RangeIt(start_LE as string, stop_LE as string, match as string) as string


Should this be "before" State instead of "after" State?  Or am I not understanding this?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Operating on a range of form elements
Reply #2 - Sep 10th, 2004 at 5:30pm
Print Post Print Post  
CapitalG,

Good catch. Thank you. Yes, that is meant to be before not after. In each case it also includes the specified elements.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
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: Operating on a range of form elements
Reply #3 - Sep 10th, 2004 at 5:42pm
Print Post Print Post  
Suggestion:  Maybe edit the original posting to change "after" to "before" so it can be copied as is?  And will allow for correct info if readers do not see the following posts, maybe landing there from a Search? 

Thanks for the good example Mark, and thanks also to CapitalG for noting that typo.
  



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



Posts: 2530
Joined: Nov 22nd, 2002
Re: Operating on a range of form elements
Reply #4 - Sep 10th, 2004 at 5:45pm
Print Post Print Post  
'tis been modified.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged