Normal Topic [Solved] XResultSet to populate menu choices? (Read 473 times)
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
[Solved] XResultSet to populate menu choices?
Mar 4th, 2008 at 1:05pm
Print Post Print Post  
Here's a snapshot of my 'ESTIMATES' form:



What I'm trying to do is this: when a user needs to create a new estimate for someone they believe is an existing client, they can enter a phone number (10 full digits) and/or a partial company name (with a minimum of 4 characters) and when they click on 'FIND' an @XResultSetSearch will be made to another db within the application named 'CLIENTS'.

Here's the programming for the command button:

Code
Select All
#include "sbasic_include.sbas"
var rs_key as Int
var vCompany as String
var vTele as String

IF @IsBlank(COMPANYNAME) = 1 AND @IsBlank(TELE) = 1 // both fields are empty.
{
	 Write("The Company and Telephone fields are blank.")
}
ELSE
{
	IF @IsBlank(COMPANYNAME) = 0 AND @IsBlank(TELE) = 1 // COMPANYNAME is not empty, but TELE is empty.
	{
		IF @LEN(COMPANYNAME) >= 4 // COMPANYNAME is at least four characters long.
		{
			//Write("You have put in a company name with at least four characters!") /// SEARCH FOR MATCHING COMPANYNAME matches using @XResultSetSearch!
			vCompany = "!COMPANYNAME=.." + COMPANYNAME + ".."
			rs_key = @XResultSetSearch(@FN, "CLIENTS", SEARCH_MODE_OR, SEARCH_SYNTAX_QA, vCompany)
			//Write("Number of XResult Records Found = " + @XResultSetTotal(rs_key))
			IF @XResultSetTotal(rs_key) = 1 // Only one record is found.
			{
				XResultSetCurrentPosition(rs_key, 1) // set our position in the record set.
				// WriteLn("Only one matching company found: " + @XResultSetValue(rs_key, "COMPANYNAME"))
				//WriteLn("The COMPANYNAME field in this form should be: " + @XResultSetValue(rs_key, "COMPANYNAME"), "The TELE field should be: " + @XResultSetValue(rs_key, "TELE"))
				COMPANYNAME = @XResultSetValue(rs_key, "COMPANYNAME")
				TELE = @XResultSetValue(rs_key, "TELE")
				CUSTNO = @XResultSetValue(rs_key, "CUSTNO")
				LNAME = @XResultSetValue(rs_key, "LNAME")
				FNAME = @XResultSetValue(rs_key, "FNAME")
				MOBILE = @XResultSetValue(rs_key, "MOBILE")
				ADDRESS1 = @XResultSetValue(rs_key, "ADDRESS1")
				ADDRESS2 = @XResultSetValue(rs_key, "ADDRESS2")
				CITY = @XResultSetValue(rs_key, "CITY")
				STATE = @XResultSetValue(rs_key, "STATE")
				ZIP = @XResultSetValue(rs_key, "ZIP")
				FAX = @XResultSetValue(rs_key, "FAX")
				REP = @XResultSetValue(rs_key, "REP")
			}
		}
		ELSE
		{
			Write("You cannot search for a company using fewer than four (4) characters.")
		}
	}
	ELSE
	{
		IF @IsBlank(COMPANYNAME) = 1 AND @IsBlank(TELE) = 0 // COMPANYNAME blank, TELE is not empty.
		{
			IF @LEN(@NUM(TELE)) = 10 // 10 digits have been supplied.
			{
				Write("You have entered 10 digits for the phone number, good job!") /// SEARCH FOR TELE using XResult.
			}
			ELSE
			{
				Write("The telephone field must have 10 digits.")
			}
		}
		ELSE
		{
			IF @IsBlank(COMPANYNAME) = 0 AND @IsBlank(TELE) = 0 // Both fields are filled.
			{
				IF @LEN(@NUM(TELE)) = 10 AND @LEN(COMPANYNAME) >= 4 // Both fields meet criteria.
				{
					Write("Hooray! You've input the Company and Tele fields correctly!")
				}
				ELSE
				{
					Write("The Telephone field must have exactly 10 digits, and the Company field must have at least 4.")
				}
			}
		}
	}
}
 



To start, I put WriteLn() comments in the code so that I could see that it was reacting properly. Please excuse how spread out my IF/ELSE statements are, I'm very new to this. This code is working when the company field is given input that results in only a single record turning up in the result set. Under that condition I would want Sesame to fill the contact info fields in the ESTIMATES form, but when more than one result turns up (some of our clients have multiple locations, or multiple contacts) I would like the user to be given a popup menu of some kind that would list the result set records, so a choice could be made.

I was thinking if I could loop through the result set and create a string array of values that looked like this:

COMPANYNAME: FNAME LNAME -- TELE

So the user would see:

HappyFun Corp.: John Smith -- 212-555-4444
StifleJoyCo.: Bob Joseph --  212-444-5555

I could then grab the rightmost 10 characters (the phone number) and use that to indicate what record to finally pull.

Am I making this more complicated than it needs to be, or is there some simple way of doing this?
Any tips, criticisms or ideas would be greatly appreciated.
I feel like a chimpanzee in the Space Shuttle, lol! (twists some dials at random)
« Last Edit: Mar 6th, 2008 at 2:05pm by Hammer »  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: XResultSet commands to populate menu choices?
Reply #1 - Mar 4th, 2008 at 2:25pm
Print Post Print Post  
This is written to work with the sample Customers database, but you should be able to adapt it to your database and requirements pretty easily. Use the technique as an example and adjust as needed.

Code
Select All
var vRS as Int
var vCount as Int
var vLoop as Int
var vLine as String
var vList as String
var vChoice as String
var vFound as Int

	vRS = @XResultSetSearch(@FN, "Customers", SEARCH_MODE_OR, SEARCH_SYNTAX_QA, "Phone=/=")
	If vRS > -1
	{
		vCount = @XResultSetTotal(vRS)
		If vCount = 0
		{
			@MsgBox("No matching records.", "", "")
		}
		Else If vCount = 1
		{
			// Fill in the values
		}
		Else
		{
			vList = ""
			For vLoop = 1 To vCount
				XResultSetCurrentPosition(vRS, vLoop)
				vLine = @XResultSetValue(vRS, "Last") + " - " + @XResultSetValue(vRS, "First") + " - " + @XResultSetValue(vRS, "Phone")
				vList = vList + vLine + ";"
			Next
			vList = @ReplLas(vList, ";", "")
			vChoice = @PopupChoiceList(vList, "SELECT A RECORD")
			If vChoice <> ""
			{
				vChoice = @Right(vChoice, 12)
				vFound = 0
				vLoop = 1
				While (vLoop <= vCount) And (vFound = 0)
				{
					XResultSetCurrentPosition(vRS, vLoop)
					If vChoice = @XResultSetValue(vRS, "Phone")
					{
						// Fill in the values
						vFound = 1
					}
					vLoop = vLoop + 1
				}
			}
		}
		XResultSetClose(vRS)
	}

 



  

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



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: XResultSet commands to populate menu choices?
Reply #2 - Mar 5th, 2008 at 2:38pm
Print Post Print Post  
I modified that a bit, Erika, and it worked out great! Thanks a lot.
  
Back to top
IP Logged