Normal Topic XLookupSourceListAll to populate combo box (Read 416 times)
Rod Weston
Member
*
Offline



Posts: 25
Joined: Aug 22nd, 2016
XLookupSourceListAll to populate combo box
Sep 9th, 2016 at 7:46pm
Print Post Print Post  
I am using XLookupSourceListAll to populate a combo box.
I am retrieving two fields from the database, but I want them sorted by the second field and only the first field displayed in the combo box.

I really appreciate all the help you are all providing. Thank you!
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: XLookupSourceListAll to populate combo box
Reply #1 - Sep 10th, 2016 at 2:28am
Print Post Print Post  
It may be easier to use the XResultSet commands to build a string array:

Code
Select All
#include "sbasic_include.sbas"

var key as int
var loop as int
var str as string
var nn as string

	// Retrieve all of the records where "First" is not blank
	key = @XResultSetSearch("Customers.db", "Customers", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!First=..")
	XResultSetSort(key, "Last:1") // Sort the record using the last name field
	nn = @XResultSetTotal(key)
	for loop = 1 to nn
		XResultSetCurrentPosition(key, loop)
                // Concatenate the "First Name" fields into a string array
		str = str + @XResultSetValue(key, "First")
		if(loop < nn)
		{
			str = str + ";"
		}
	next
	XResultSetClose(key)
	writeln(str)
 



Once you have "str" (the newly constructed string array), you can use that to populate the combo box.

You may also be able to do it with the string array produced by @XLookupSourceListAll. After you get your string array, change the string array separator from the default semi-colon to the new-line character and call @SortStringArray, which will sort on the first element. Accessing the string array will then give you the element pairs. If you re-access that, with string array separator set back to semi-colon, you can derive either the first or second element and build a new string array using just that element.

Code
Select All
#include "sbasic_include.sbas"

var aa as string
var ab as string
var ac as string
var ad as string

var loop as int
var str as string
var nn as string

aa = @XLookupSourceListAll(@fn, "..", "First", "Last;First")
SetStringArraySeparator(@chr(10))
ab = @SortStringArray(aa, 0)

nn = @CountStringArray(ab)
writeln(nn)
for loop = 1 to nn
	SetStringArraySeparator(@chr(10))
	ac = @AccessStringArray(ab, loop)
	SetStringArraySeparator(";")
	ad = @AccessStringArray(ac, 2)
	str = str + ad
	if(loop < nn)
	{
		str = str + ";"
	}
next
writeln(str)

 



Here again, the "str" variable would be used to populate the combo box.
  

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