Page Index Toggle Pages: [1] 2 3  Send Topic Send Topic Print Print
Very Hot Topic (More than 25 Replies) Relational / Combo-Box Programming help? (Read 5338 times)
NWade
Member
*
Offline


No personal text

Posts: 3
Joined: Jul 7th, 2004
Relational / Combo-Box Programming help?
Jul 7th, 2004 at 3:02am
Print Post Print Post  
Okay all,

I'm brand new to Sesame - am having to work on it for a client; but I've been a PHP/mySQL and MS-SQL junkie for the last 2 years...  So SBASIC is all new to me, and I'm having to mentally re-adjust to the limited access and methods that Sesame uses to access the DB.

I'm trying to implement something that SHOULD be possible, but I'm not sure what the best method is to implement it...  I have a Database of family members, and I want to create what I would term in SQL as a "foreign key" relationship between records.  Tips, suggestions, or advice are certainly appreciated!

Basically, I have a numeric field "personID" to uniquely identify each person/record (a "primary key" in SQL terms).  I also have the field "fatherID" - the idea being that this field will refer to an existing "personID" record if that person's father is already in the database, so that parent/child relationships can be tracked.

However, I don't want to require the users to remember the actual ID numbers - so I was hoping to display a list-box or combo-box in the form, and have it populate (On Form Entry) with the names of all of the males currently in the database.  When a selection is made, the ID number of that person could be stored in the "fatherID" field; and on future viewings, the name of the selected "father" could be automatically retrieved and displayed on the form.

Of course, the first issue is that the combo-box needs to display text information (the potential father names), while the value to be saved is numeric.  Maybe I'm spoiled, but in HTML forms you can have combo/list-box items display one thing, but their actual value be something else entirely (i.e. a "key-value" pair).  I can't see a way at the moment (except perhaps with a static array or something??) to retrieve the values from 2 columns of a database at once, and keep them associated with each other while the user selects one.  They need to stay associated to guarantee that the proper ID number is recorded - (i.e. going back and looking up the father's name to retrieve his personID from the database after selecting him is not acceptable, as the names themselves are not going to be guaranteed to be unique).

Any thoughts, comments, concerns?  I see a couple of possible ways of doing it; but I'm hoping your suggestions will point to a clearer or less-cumbersome solution than what I'm envisioning...

Thanks, take care,

--Noel
noel_wade@hotmail.com
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Relational / Combo-Box Programming help?
Reply #1 - Jul 7th, 2004 at 11:28am
Print Post Print Post  
I'm not sure how literal you are being when referring to "parent" IDs and etc... but you may want to reconsider using relational linking unless it is absolutely necessary. The occassion in which relational linking is warranted in Sesame (as opposed to natural linking) is where a single child that is unique (and must remain "normalized") appears under multiple differing parents. Otherwise use natural linking. It is much simpler and faster.

Unlike MySql, Sesame is not dividing your database into multiple standalone tables. Instead, it uses a variation of an outline (lists within lists) to maintain hierarchy.

To create a combo box that shows one value and returns another, use an unbound combo box. Then use the "GlobalValue" functions to populate the combo box and "match" a string to a numeric to generate the key value. GlobalValues are tables of values stored with the database that are "keyed" off of an arbitrary string.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Relational / Combo-Box Programming help?
Reply #2 - Jul 7th, 2004 at 11:35am
Print Post Print Post  
If your name/number pairs are coming out of database records (as opposed to being static lists) you can use commands like XLookupSourceListAll to create a composite value for your combo box or picklist and parse the number off the selected value.
  

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


No personal text

Posts: 3
Joined: Jul 7th, 2004
Re: Relational / Combo-Box Programming help?
Reply #3 - Jul 7th, 2004 at 6:10pm
Print Post Print Post  
Mark -

Thanks for the advice... However, since these records are all part of the same DB, I can't make them "natural" parent/child records.  Plus, I am looking to have both "fatherID" and "motherID" fields (I left out "motherID" to simplify my example), so that full lineage and bloodlines may be tracked for a medical study.  FYI: I have medical history records that are "natural" children of each person's main record, to track each major health issue as a seperate record...  So I'm already using "natural" linking in the app. Wink


Hammer -

That was one avenue I was pursuing, but I didn't know how to retrieve multiple fields at once.  Where is "XLookupSourceListAll" documented?  I can't find it in the Sesame Programming Guide... at least, not in the table on pg. 38 nor in the "Retrieving Data" or "Advanced Functions" sections.

Which triggers a thought:  Has the Lantica team considered posting an SBASIC "API reference" on the website?  One of the nice things about mySQL.com and PHP.net are that they have complete lists of keywords and built-in functions on their websites...  I don't see that on the Lantica website or on sesamedatabase.com, but correct me if its there and I'm blind! ;-P

Thanks a bunch, take care,

--Noel
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Relational / Combo-Box Programming help?
Reply #4 - Jul 7th, 2004 at 6:24pm
Print Post Print Post  
It is one of the new commands added in a recent update. Everything added since the original release is contained in a Documentation Supplement that is available in the same place you go to download the program updates. Take a look at the new X commands, and also the StringArray functions, whcih are very handy for operating on the values returned by the X commands.  Smiley

For a brief summary of the new commands, take a look at the Change Log.

You may want to consider looking into the Inside Sesame newsletter. I know that recent issues have included some articles on different ways to generate and work with picklists and combo boxes.
  

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


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Relational / Combo-Box Programming help?
Reply #5 - Jul 21st, 2004 at 6:39pm
Print Post Print Post  
Is it possible to auto-populate a combo box with a string of results built from an xlookup command, while STRIPPING OUT dupes and alphebetizing, or can this only be done with the popup menu command?

We prefer to use combo boxes because they are neat, clean, easy to use, and we can control the placement, size and color of the box and list.

Also, we NEED the 'auto complete' properties of a combo box rather than having to hunt through a large list of choices.

Am I overlooking something obvious?

Thanks,
Steve
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Relational / Combo-Box Programming help?
Reply #6 - Jul 21st, 2004 at 6:57pm
Print Post Print Post  
Quote:
Is it possible to auto-populate a combo box with a string of results built from an xlookup command, while STRIPPING OUT dupes and alphebetizing, or can this only be done with the popup menu command?


@XLookupAll will return a semicolon separated list of values. @SortStringArray can sort the list. PopulateListElement can hand the list to a combo box. You'll have to use the string array functions to create a custom duplicate stripping routine.

  

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


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Relational / Combo-Box Programming help?
Reply #7 - Jul 21st, 2004 at 6:59pm
Print Post Print Post  
Thanks for the tips!

I'll head off in that direction!

Steve
  
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Relational / Combo-Box Programming help?
Reply #8 - Jul 22nd, 2004 at 10:01pm
Print Post Print Post  
Erika,

I've got the programming done and I will post it in the programming examples section of this forum, but I have 1 more issue.

Combo box's dont seem to follow the traditional  'programming events' rules. On Element Entry and On Element Exit dont do anything. I THINK I could only get the program to fire when I used On Element Immediate change.

My programming works fine if I put it in a command button.

Is this documented somewhere in the manual, or is this a bug?

The below program was pasted in LE named MFGR On Element Exit:

var vduped as string
var vstring as string
var vcollections as string
var vcollection as string


if @mode() = 2 and mfgr <> "" then
{
vcollections = @XLookUpAll(@FN, mfgr, "mfgr", "collection")
vduped = @sortstringarray(vcollections, 0)

while @len(vduped)>0
{
if @instr(vduped, ";")>0 then vstring=split(vduped, ";") else vstring = split(vduped, @newline())
if @instr(vcollection, vstring)<1 then vcollection = vcollection + vstring + ";"
vstring = ""
}
populatelistelement(collection, vcollection)
}

Edit: MFGR and Collection are both Combo Boxes.
Edit again: Program does not work in MFGR On Immediate Change, either.

Thanks for the help!

Steve
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Relational / Combo-Box Programming help?
Reply #9 - Jul 23rd, 2004 at 12:23pm
Print Post Print Post  
Steve,

Both OnEntry and OnExit programs are triggering for me on a combo box. We did fix a small issue a few days ago where OnChange did not refresh immediately under certain circumstances, but OnEntry and OnExit seem to be doing fine.

Try just putting a WriteLn in the event to see if it's running at all. Perhaps your conditions are not occuring as you think they are.
  

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


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Relational / Combo-Box Programming help?
Reply #10 - Jul 23rd, 2004 at 1:29pm
Print Post Print Post  
I had at least 5 writelns in the program until I got it to work with a button. With a button, it works flawlessly.

I then pasted the same program into the combo box, in serveral different events, but no luck.

In particular (and maybe the only issue) is the second combo box is not supposed to fire unless the first combo box is not blank.

Is it possible the second combo box cannot tell if the first combo box is filled in? (a bug?)


Steve
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Relational / Combo-Box Programming help?
Reply #11 - Jul 23rd, 2004 at 1:37pm
Print Post Print Post  
Steve,

You're telling me that you don't think the OnEntry and OnExit events are running for the combo box. I'm suggesting that you put nothing but a WriteLn in the event, just to see if it is running at all. If the event runs, but your particular code is not doing what you think it should, then you may not be meeting the conditions in your code.

If the button can tell that a combo box is blank, then so can another combo box. It is actaully the programming environment checking this, not any particular element.
  

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


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Relational / Combo-Box Programming help?
Reply #12 - Jul 23rd, 2004 at 1:46pm
Print Post Print Post  
Oh, good point. I just added writelns to the combo box on element exit and on element entry and tested it in preview mode.

the results........NOTHING!

Just for kicks I pressed the button to do the xlookups and populatelistelement. The results.....CRASH!

I'm restarting the server now becuase Sunlock wont unlock the dsr.

I guess thats what I get for trying to do an xlookup in preview mode.

Steve

edit: restarted sesame server and tried to open DSR file.

ERROR: Database does not exist.

Go figure!
  
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Relational / Combo-Box Programming help?
Reply #13 - Jul 23rd, 2004 at 2:36pm
Print Post Print Post  
OK. After restoring a backup and redoing some programming, I tested all the element events for my two combo boxes. Here are the results:

"On Element Change" fires after changing AND exiting the LE.

On Element Entry does nothing
On Element Exit does nothing
On element Immeditate change does nothing


Results are the same for both of my combo boxes. This explains why my populatelistelements were not working.

Any ideas?

Steve
  
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Relational / Combo-Box Programming help?
Reply #14 - Jul 23rd, 2004 at 3:03pm
Print Post Print Post  
Erika,

I see whats happening now.

in Update mode, my combo boxes seem to be working fine.

I was testing my program in Search(retrieve spec) mode.

I put my programming in On Element Change and it is working fine for me, but as mentioned before, it wont work in the other modes AS LONG AS IM IN SEARCH MODE.

Is this the correct functionality?

Sorry for the trouble.
Steve
  
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send Topic Send Topic Print Print