Hot Topic (More than 10 Replies) Multiple condition combo box population (Read 1812 times)
GordonB
Member
*
Offline



Posts: 6
Joined: Jun 10th, 2015
Multiple condition combo box population
Sep 26th, 2015 at 9:15pm
Print Post Print Post  
Hi All,
I'm new to Sesame and need some help.

I have three combo boxes the first combo box looks up the product file and you then select the Supplier when you have selected the supplier this then populates the second combo box with all the categories of product from that supplier. This all works fine. I now need to populate the third combo box with only the products by the supplier from the first combo box and the category from the second combo box 

Here is how I envisage this to be:


  Combo box 1             Combo box 2      Population of combo box 3
  Supplier    Category    Product 
   Sunkist    Soft Drinks       Orange   
   Apple   
   Berry   


If anyone could shed any light on this, it would be greatly appreciated
Thanks in advance,
GordonB

  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Multiple condition combo box population
Reply #1 - Sep 28th, 2015 at 4:59pm
Print Post Print Post  
In programming for Product:
Code
Select All
if((Supplier = "Sunkist") and (Category = "Soft Drinks")) then
  PopulateListElement(Product, "Orange;Apple;Berry")
else if((Supplier = "Pepsi") and (Category = "Soft Drinks")) then
  PopulateListElement(Product, "Cola;Diet;Pepsi Zero")
 end if
 



Etc.

You will probably want this, or something like it, in Enter programming for the Product field, so it only gets the list together when the user is ready to use it. Otherwise, you will need to make sure the user enters the fields in order, which is not a good idea if they have a mouse.

Remember to clear this if the user changes either of the "previous" fields.
  

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



Posts: 6
Joined: Jun 10th, 2015
Re: Multiple condition combo box population
Reply #2 - Sep 28th, 2015 at 9:50pm
Print Post Print Post  
Hi

I don't think i explained it very well. I have 100 suppliers 50 categories and about 1000 products.
This is what I have in the make (Supplier)element.

I now need to do something very much like this but to select the products from the make and category.

var vList as String

     Clear(Category)
     
      //Get all the Categories from the selected make
     vList = @XLookupAll(@FN,Make,"Products!Make","Category")
     
      //Remove duplicates from list.
     vList = @UniqueStringArray(vList)

      //Sort the List
     vList = @sortStringArray(vList,0)

      //Add each item on the list to the Category combo box.
     PopulateListElement(Category,vList)

  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Multiple condition combo box population
Reply #3 - Sep 29th, 2015 at 1:09pm
Print Post Print Post  
Basically, you want a lookup with multiple criteria...

Your best bet would probably be using XResultSet commands. @XResultSetSearch allows for multiple search criteria.

If you are more comfortable with the XLookup family, you can use XLookupSourceListAll to return all three relevant fields from all 1000 product records, then loop through the results, comparing Supplier and Category to the selected form values, and if they match, using the Product field to populate the list element.
  

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



Posts: 6
Joined: Jun 10th, 2015
Re: Multiple condition combo box population
Reply #4 - Oct 1st, 2015 at 9:06pm
Print Post Print Post  
Hi
Sorry I'm to new to Sesame. QA4 Qawin I was well into but this is a bit over my head. Can anyone help me a bit more with some sort of sample.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Multiple condition combo box population
Reply #5 - Oct 2nd, 2015 at 6:14pm
Print Post Print Post  
Here is the example for using a XResultSet given in the commands/functions help in the SBasic editor, modified to be closer to what you need.

To get to function/command help in the SBasic editor, right click on the surface of the SBasic editor and select "List Browser" from the menu that appears. Type the first few letters of a command or function to scroll right to that function. Many have full examples.

This example show you how to use more than one search criteria and how to retrieve a field value

Code
Select All
#include "sbasic_include.sbas"

var vRSHandle as int
var vNoOfRecords as int
var vLoop as int
var vSearchCriteria1 as string
var vSearchCriteria2 as string
var vProduct as string
var vProductList as string

        // clear the list
        vProductList = ""

        // set the search criteria to match values from other combos
        vSearchCriteria1 = "!Supplier=" + supplier
        vSearchCriteria2 = "!Category=" + category

        // get records matching the two combo box values
        vRSHandle = @XResultSetSearch(@fn, "YourForm", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, search_criteria1, search_criteria2)

        // make sure we got an open result set
        if(vRSHandle > -1)
        {
                // how many records did we get
                vNoOfRecords = @XResultSetTotal(vRSHandle)

                // loop through the records
                for vLoop = 1 to vNoOfRecords
                        // set the record counter to the loop
                        XResultSetCurrentPosition(vRSHandle, vLoop)

                        // get the value of the product field
                        vProduct = @XResultSetValue(vRSHandle, "Product")

                        // add the value to the list
                        vProductList = @AppendStringArray(vProductList, vProduct)
                next
                // use the list to populate the combo box
                PopulateListElement(Product, vProductList)

                // close the result set
                XResultSetClose(vRSHandle)
        }
 



Of course, you may need to adjust things to match your actual field and element names.
  

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



Posts: 6
Joined: Jun 10th, 2015
Re: Multiple condition combo box population
Reply #6 - Oct 5th, 2015 at 8:15pm
Print Post Print Post  
Thanks for you help so far. But i am very very new to this. I don't want to pester you too much but I don't understand the following.

@XResultSetSearch(@fn, "YourForm", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, search_criteria1, search_criteria2)

The file/db the information is retrieved from is "Products". The file/db I am programming in is "Repair Record"

Please could you give me a little more help.

once again my apologies for being so ignorant.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Multiple condition combo box population
Reply #7 - Oct 5th, 2015 at 8:53pm
Print Post Print Post  
If the application file you wish to retrieve from is "Products.db" and the form name in that file you want to get information from is "Products", that line should read something like:

Code
Select All
vRSHandle = @XResultSetSearch("Products.db", "Products", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, search_criteria1, search_criteria2)
 



What that line means:
Open the application "Products.db" and look in the "Products" form for records that match both of the search criteria. Put all of those records in a "result set" - basically a list of matching records.

No need to apologize. We welcome all questions about Sesame.
  

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



Posts: 6
Joined: Jun 10th, 2015
Re: Multiple condition combo box population
Reply #8 - Oct 6th, 2015 at 10:00pm
Print Post Print Post  
No matter what I do I get an up arrow under the S of search_criterial1.

vRSHandle = @XResultSetSearch(@fn, "YourForm", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, search_criteria1,
search_criteria2)



The result is always the same no matter what I use as @fn and "YourForm".
Shows Line:544 Position 62. there is no Line 544

I have tried and tried and read as much as I can but no joy.
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Multiple condition combo box population
Reply #9 - Oct 7th, 2015 at 2:30am
Print Post Print Post  
Not sure if this is your problem, but...

Mark had a typo in the code example he provided. His variable declarations are "vSearchCriteria1" and "vSearchCriteria2", but in the @XResultSetSearch() command, it was listed as "search_criteria1" and "search_criteria2". Those are missing the leading "v" and have underscores in them.

And I noticed that your posting showed it that way too.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Multiple condition combo box population
Reply #10 - Oct 7th, 2015 at 3:30am
Print Post Print Post  
Carl is right. Not really a typo, so much as a careless mistake. I composed the code by editing the example provided in Sesame in the forum's editor, rather than trying it in Sesame - always a mistake.

My bad and another good catch by Carl.
  

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



Posts: 6
Joined: Jun 10th, 2015
Re: Multiple condition combo box population
Reply #11 - Oct 7th, 2015 at 5:37pm
Print Post Print Post  
It works. Thank you both very much. Grin Grin Grin
  
Back to top
 
IP Logged