Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) drop down menu (Read 1603 times)
debmckee
Full Member
***
Offline



Posts: 123
Joined: Oct 5th, 2011
drop down menu
Nov 29th, 2011 at 7:03pm
Print Post Print Post  
Obviously I have a lot to learn everyone out there is teaching me!  I am trying to program a drop down list of a customer file so that when entering sale memos, po's etc. you can choose the customer name.  What I have so far (that doesn't work is)

populateListElement(cust lookup1,@xuserselect(@fn,"contacts!contacts"))

I thought I would take one step at a time........
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: drop down menu
Reply #1 - Nov 30th, 2011 at 3:17am
Print Post Print Post  
You'll probably want to use something more along these lines:

var vList as String

// Get all Contacts from Contacts form
vList = @XListValues(@Fn, "Contacts!Contacts")

// Initialize the Combo Box with unique sorted values
PopulateListElement(TransName, @UniqueStringArray(@SortStringArray(vList, 0)))
  


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: drop down menu
Reply #2 - Nov 30th, 2011 at 4:53am
Print Post Print Post  
Carl Underwood wrote on Nov 30th, 2011 at 3:17am:
You'll probably want to use something more along these lines:

var vList as String

// Get all Contacts from Contacts form
vList = @XListValues(@Fn, "Contacts!Contacts")

// Initialize the Combo Box with unique sorted values
PopulateListElement(TransName, @UniqueStringArray(@SortStringArray(vList, 0)))


Carl,
Your post makes clear a point I'd like to make. It is often a good idea to use variables even in cases where you could (but probably shouldn't) nest functions. By using a intervening string variable, as you did, you can use writeln to see the value of the variable during development to make sure that each step of the procedure is running the way you want it too.

I don't think that this is going too far:
Code
Select All
var vList as String
var vList2 as String
var vList3 as String

// Get all Contacts from Contacts form
vList = @XListValues(@Fn, "Contacts!Contacts")

// Initialize the Combo Box with unique sorted values
vList2 = @SortStringArray(vList, 0)
vList3 = @UniqueStringArray(vList2)
PopulateListElement(TransName, vList3)
 



It adds visual clarity to the code, and also makes it easier to debug. It may run a tiny bit slower, but can be easily optimized after you know that it is working.

And, as I've been saying since Sesame 1.0, never use a field/element when a variable will do. Variables are many times faster and safer than elements. Only use an element to get the value initially, or to write the final result back.
  

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



Posts: 123
Joined: Oct 5th, 2011
Re: drop down menu
Reply #3 - Nov 30th, 2011 at 5:43pm
Print Post Print Post  
I think i am missing something. 
This is my code
var vList as String
var vList2 as String
var vList3 as String

// Get all Contacts from Contacts form
vList = @XListValues("s:\pacific coast fruit products.db", "Contacts!le5")

// Initialize the Combo Box with unique sorted values
vList2 = @SortStringArray(vList, 0)
vList3 = @UniqueStringArray(vList2)
PopulateListElement(cust lookup0, vList3)


contacts is my external database, le5 is the element in the lookup file.  Cust lookup0 is the target field in the operating form.
  
Back to top
 
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: drop down menu
Reply #4 - Dec 1st, 2011 at 3:35am
Print Post Print Post  
Lots of helpful info in this thread.

Debmckee, from The Cow's post, you might want to try the below code to find out if the 'xListValues command is working...

Quote:
var vList as String
var vList2 as String
var vList3 as String

// Get all Contacts from Contacts form
vList = @XListValues("s:\pacific coast fruit products.db", "Contacts!le5")
write("My Lookup found: " + vList)

// Initialize the Combo Box with unique sorted values
vList2 = @SortStringArray(vList, 0)
vList3 = @UniqueStringArray(vList2)
PopulateListElement(cust lookup0, vList3)


Consider adding another 'write' or 'writeln' command to show what vList3 is doing, too.
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: drop down menu
Reply #5 - Dec 1st, 2011 at 4:10am
Print Post Print Post  
In addition to the writeln that Steve suggested (thanks Steve), you might also use an @error right after the @XListValues. There are also a couple of other related error routines that might be useful.

Just guessing, but I'd look very carefully at the file path and make sure that it is correct for the server (not the client running that code). If so, I'd look next at the field path in the next argument.
« Last Edit: Dec 1st, 2011 at 2:07pm by The Cow »  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: drop down menu
Reply #6 - Dec 1st, 2011 at 4:47am
Print Post Print Post  
The Cow wrote on Nov 30th, 2011 at 4:53am:
Carl,
Your post makes clear a point I'd like to make. It is often a good idea to use variables even in cases where you could (but probably shouldn't) nest functions. By using a intervening string variable, as you did, you can use writeln to see the value of the variable during development to make sure that each step of the procedure is running the way you want it too.

Yes, I know. Embarrassed

Actually, I almost rearrainged it to avoid having you or Erika see it that way. Smiley
But, this happens to be the way it appears in one of my apps, so I just cut & pasted it that way.

BTW, I have found that it's 6 times faster to sort first, then run unique, rather than the other way around.
  


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: drop down menu
Reply #7 - Dec 1st, 2011 at 1:51pm
Print Post Print Post  
Carl Underwood wrote on Dec 1st, 2011 at 4:47am:
Actually, I almost rearrainged it to avoid having you or Erika see it that way. Smiley


Rearranged it so it used more or fewer variables? I was actually trying to convey that it was a good example of their use. I think my example is actually a bit extreme in this case in that it likely that the actual problem is in the very first function (i.e.: @XListValues).
  

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: drop down menu
Reply #8 - Dec 1st, 2011 at 2:09pm
Print Post Print Post  
debmckee wrote on Nov 30th, 2011 at 5:43pm:
// Get all Contacts from Contacts form
vList = @XListValues("s:\pacific coast fruit products.db", "Contacts!le5")

By any chance, is "s:\pacific coast fruit products.db" the application you are already in? If so, you can just use @FN - which means 'use the current application' - instead of a full path, which can cause issues if you really want to be using the application you are already in.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: drop down menu
Reply #9 - Dec 1st, 2011 at 2:23pm
Print Post Print Post  
Deb,

I also see that you are using "le5" as the source element. That fact that it is named "le5" increases the odds that that particular element is static and cannot contain any data. Have you tried using any other elements?
  

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



Posts: 123
Joined: Oct 5th, 2011
Re: drop down menu
Reply #10 - Dec 1st, 2011 at 5:30pm
Print Post Print Post  
When I entered the code to check the xlistvalues it just came up with "my lookup found: my look found.

So I assume that his means the fault lies in the xlistvalues.  I originally had @fn and switch to full path name just in case.  I have tried other fields.  Now, i don't know if this makes a difference, but it is the same application, contacts is the name of another database and the form within the database.  The element name  is le5.  The values in this field are results of a programmed command.  I did check the field and made sure that it has values in it.  Plus I tried other elements in case the fault was with the element itself.  Any other suggestions?

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



Posts: 2530
Joined: Nov 22nd, 2002
Re: drop down menu
Reply #11 - Dec 1st, 2011 at 6:14pm
Print Post Print Post  
debmckee wrote on Dec 1st, 2011 at 5:30pm:
When I entered the code to check the xlistvalues it just came up with "my lookup found: my look found.


That's very odd. Are you sure you have Carl's code exact?

Quote:
So I assume that his means the fault lies in the xlistvalues.  I originally had @fn and switch to full path name just in case. 


If it is the same app, use @fn. Less prone to human error.

Quote:
I have tried other fields. 


Where any of these non-static? And, if so, what was the result?

Quote:
Now, i don't know if this makes a difference, but it is the same application, contacts is the name of another database and the form within the database.  The element name  is le5. 


Is le5 static?

Quote:
The values in this field are results of a programmed command. 


Can you simply put the results of that programming into your menu, rather than using a intervening field? If the only purpose of this field is to temporarily store this info, replace it with a global variable.

Quote:
I did check the field and made sure that it has values in it. 


How did you check this? What sort of element is it?

Quote:
Plus I tried other elements in case the fault was with the element itself.  Any other suggestions?


To what result?

Quote:
thanks!


You're welcome.
  

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



Posts: 123
Joined: Oct 5th, 2011
Re: drop down menu
Reply #12 - Dec 1st, 2011 at 6:36pm
Print Post Print Post  
1.  None of the fields are static.  LE5 is a field to store the data I want in the lookup which is the company name + their id no.  I checked for data by making sure that the data is in the preview file and the main file.  However, I am waiting for an appt. time for focused support on a few issues, one of which is the main application does not seem to close properly sometimes resulting in me having to unlock or even unload the file frequently.  I was just looking in the error log for a different issue and noticed that everytime I tried to run the above command I got an error msg of @fn failed to open.
Could they be related?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: drop down menu
Reply #13 - Dec 1st, 2011 at 6:45pm
Print Post Print Post  
debmckee wrote on Dec 1st, 2011 at 6:36pm:
I was just looking in the error log for a different issue and noticed that everytime I tried to run the above command I got an error msg of @fn failed to open.
Could they be related? 


Very likely.
  

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


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: drop down menu
Reply #14 - Dec 2nd, 2011 at 1:40am
Print Post Print Post  
Debmckee,

This may not help solve the problem you are presently dealing with; however since people are talking about walking through your code I figured I would share a few basic sbasic commands the Lanticans have given us that make our lives a bit easier. (Just incase you are not making use of them already)

I like to use these Sbasic commands on a test button to help me identify I am using the correct info.  It gives you some insight when dealing with  Xlookups and stuff like that.

// utility for identifying information
Writeln("app is " + @application)
Writeln("db is " + @database)
Writeln("filename is " + @filename)
Writeln("layout is " + @layout)
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print