Hot Topic (More than 10 Replies) Lookup Table Programming (Read 1520 times)
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Lookup Table Programming
Nov 21st, 2005 at 5:50am
Print Post Print Post  
Hi -

I am trying to create a lookup table using an array of values, as described in Appendix 2 of the Programming Guide.

When I test the program, everything appears ok; however, when I try it in preview mode, I get the message "[b]Array index overflow.[/b]"

Here's the programming I am using in global code:

[code]
stat LU1 as array[169,2] of String

LU1[1,1]="Air-Fresheners";LU1[1,2]="12"
LU1[2,1]="Aluminum-Foil";LU1[2,2]="11"
  etc for
LU1[3,1]
 through
LU1[167,1]
LU1[168,1]="Wines";LU1[168,2]="18"
LU1[169,1]="Yeast";LU1[169,2]="5"
[/code]

And here's the programming I am using in Category::On Element Exit

[code]
var i as Int
var foundit as String

If Category <> "" Then
{
For i = 1 to 169
If LU1[i,1] = Category Then
{
Aisle = LU1[i,2]
foundit = "yes"
i = 169
Throwfocus(Qty)
}


Next
If foundit <> "yes" Then
{
@Msgbox("'" + Category + "' not found in table.","","")
Clear(Category)
Goto Category
}
}

[/code]

So [b][i]now[/i][/b] where am I going wrong?

I would love to get this done before I go to sleep tonight, and I'm ready to go to sleep. So, if anyone is out there with a "solution," I would appreciate hearing from you.

Also, if there is an alternative approach that you think would be better in this situation, I would like to hear it.

Thanks!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Lookup Table Programming
Reply #1 - Nov 21st, 2005 at 2:51pm
Print Post Print Post  
Morning Spencer,

I just tried your code here and I do not get an error. Try commenting out all of the Category::On Element Exit code and see if you still get the error.

If you do then look at the code in global code where you are filling in the array. Look for something like

LU1[468,1]="Wines";LU1[168,2]="18"

or another typo of some sort in the brackets.

-Ray
« Last Edit: Nov 21st, 2005 at 6:11pm by Ray the Reaper »  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Lookup Table Programming
Reply #2 - Nov 21st, 2005 at 4:59pm
Print Post Print Post  
Ray -

I'm a little confused.  If I comment out all of the Category::On Element Exit programming then how could my lookup possibly work?

When you say that you "tried the code and do not get an error" do you mean that you actually performed a lookup in preview mode?

Once again, when I test the programming - it clears just fine.  It is only when I actually try to perform a lookup in Preview Mode that I get the "Array Index Overflow" message.  That is followed, by the way, by a message that says "Error:  A runtime SBASIC error has occured.  Please close this form and repair the condition before continuing."

Unrelated programming that I have in the data base, does not run either.

I even went ahead and "reconciled" my dsr file to the db file and tested the db file.  I get the same message.

In any event, I did as you suggested and commented out the Category::On Element Exit programming and it made no difference.  Once again, the program test passed; however when testing the database in preview mode, I received the same two messages.

While I am waiting to hear from you, I will try to look at the 169 entries to be sure they are accurate (oh vey!  what a tedious task).  lol  
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Lookup Table Programming
Reply #3 - Nov 21st, 2005 at 5:46pm
Print Post Print Post  
[quote author=SpencerWulwick  link=1132552232/0#2 date=1132592349]Ray -

I'm a little confused.  If I comment out all of the Category::On Element Exit programming then how could my lookup possibly work? 
[/quote]

That is the point. It won't run, Only the global code will run and if the error still happens then the error is in Global Code

[quote] When you say that you "tried the code and do not get an error" do you mean that you actually performed a lookup in preview mode? [/quote]

I mean I ran your code in a runtime enviroment similiar to what you are doing.

[quote] Unrelated programming that I have in the data base, does not run either. [/quote]

Once an Sbasic Error has occured no other programming will run until the error is fixed and/or Sesame is reloaded.

[quote] In any event, I did as you suggested and commented out the Category::On Element Exit programming and it made no difference.  Once again, the program test passed; however when testing the database in preview mode, I received the same two messages. [/quote]

Have a real close look at your global code then.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Lookup Table Programming
Reply #4 - Nov 21st, 2005 at 5:46pm
Print Post Print Post  
Ray -

You're a genius!

I found 3 types of errors:

(1) a "mismatch" such as you described, something like:

LU1[468,1]="Wines";LU1[168,2]="18"

(2) a duplicate entry, something like

LU1[12,1="Produce";[LU1[12,2]="33"
 ... and waay, waay down
LU1[12,1="Greeting Cards";[LU1[12,2]="44"

What happened is that I simply "dropped" the zero when I got to my 120th entry.

(3) a reversed code, something like:

I had listed LU1[122,1="Bags";[LU1[2,122]="13"

Having discovered this, is this not something that could be built into the "programming test" to save us an awful lot of trouble utilizing this type of lookup?

Lastly, given the tedious work in setting this up, would you recommend an alternative lookup for this many (169) required entries?  And, if so, what do you think would be my best choice (since there are several).

Thanks!

P.S.  Just as I posted this, your last message was posted, right when I was doing my "save" of my message.   lol
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Lookup Table Programming
Reply #5 - Nov 21st, 2005 at 6:11pm
Print Post Print Post  
[quote author=SpencerWulwick  link=1132552232/0#4 date=1132595212]
(3) a reversed code, something like:

I had listed LU1[122,1="Bags";[LU1[[color=Red]2,122[/color]]="13"[/quote]

This would cause it. The other ones would cause wrong values to be returned

[quote]Having discovered this, is this not something that could be built into the "programming test" to save us an awful lot of trouble utilizing this type of lookup?[/quote]

This I am not sure about.

[quote]Lastly, given the tedious work in setting this up, would you recommend an alternative lookup for this many (169) required entries?  And, if so, what do you think would be my best choice (since there are several).[/quote]

Well you could store the 169 entries in a text file and then parse that into a Static array in Global Code. Just loop from 1 to 169 and read a line of the file at a time.

You could create another database in the same application and have it store the 169 entries. This way if the number ever increases you do not have to change any code.

You could use a StringArray rather than a formal array and search through it to find the correct category and parse out the aisle number from that

As to which way is best well that all depends on you and how you want to do it.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Lookup Table Programming
Reply #6 - Nov 21st, 2005 at 6:22pm
Print Post Print Post  
Quote:
Having discovered this, is this not something that could be built into the "programming test" ...?


No, all values (including array indexes) are not "realized" until runtime. SBasic is a compiled language.
  

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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Lookup Table Programming
Reply #7 - Nov 21st, 2005 at 11:28pm
Print Post Print Post  
Hi -

Thanks folks!

That tells me most of what I need to know on the topic and I appreciate it.
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
SpencerWulwick
Senior Member
Members
*****
Offline



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Lookup Table Programming
Reply #8 - Nov 22nd, 2005 at 1:24am
Print Post Print Post  
Hi -

Grrr!  I cannot believe that I am back in this same thread (and so soon at that).  Just when I thought I had everything under control another problem has cropped up.

The following entries are coming out on separate lines in my combo box and, therefore, the lookup will not work.

Code
Select All
LU1[93,1]="Jams, Jellies";LU1[93,2]="13"
LU1[94,1]="Jello, Pudding";LU1[94,2]="9" 


In my combo box, Jams and Jellies are appearing as two separate entries.  I can only select one or the other; however, the lookup fails.

If I type (in the combo box) Jams, Jellies, the entry is accepted and the appropriate lookup is completed.

Come on, now, this just CAN'T be me.  It just CAN'T BE!!!!

Help!!!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Lookup Table Programming
Reply #9 - Nov 22nd, 2005 at 2:33am
Print Post Print Post  
Have you tried?
Code
Select All
PopulateListElement(ComboBoxName, "jams, jellies;stuff1;stuff2")
 


Note the semicolons separating the different list items and the comma between jams and jellies.
  

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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Lookup Table Programming
Reply #10 - Nov 22nd, 2005 at 2:41am
Print Post Print Post  
Mark,

I'm confused again since I provided the code above and it does include semicolons. Perhaps the code format made it difficult to see so here, once again, are the two line items I gave as an example.

LU1[93,1]="Jams, Jellies";LU1[93,2]="13"
LU1[94,1]="Jello, Pudding";LU1[94,2]="9"


I followed the programmers guide, appendix 2 very carefully when I started this.

Thanks!
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Lookup Table Programming
Reply #11 - Nov 22nd, 2005 at 2:57am
Print Post Print Post  
I am suggesting that you should populate your combo box using the subroutine called "PopulateListElement". PopulateListElement uses semicolons to separate the different items on the list. You will probably want to use the same strings as appear in your array, so as to avoid having to enter them twice. You can use a "for loop" to loop through your array, concatenating the strings into a single string variable, separating each item with a semicolon. Pass the resulting string to PopulateListElement - to fill out the appearing list in your combo box.

Something like (untested):
Code
Select All
var loop as int
var str as string

str = ""
for loop = 1 to 168
  str = str + LU1[loop, 1] + ";"
next
str = str + LU1[169]
PopulateListElement(ComboBoxName, str)
 



Though I must admit I would be a bit intimidated by a combo box with 169 choices on it. In any case, using PopulateComboBox will allow you to add an item that has a comma (",") in the middle of it.
  

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



Posts: 677
Location: Wilton Manors, Florida
Joined: Jan 16th, 2005
Re: Lookup Table Programming
Reply #12 - Nov 22nd, 2005 at 3:55am
Print Post Print Post  
Hi -

Spencer said:

[quote]Come on, now, this just CAN'T be me.  It just CAN'T BE!!!! [/quote]

Well, it [b][size=24]was too[/b][/size] Spencer and what we really need is a new icon depicting someone eating his or her own words!!!!     lol

I had so much difficulty with the global coding which was somewhat complex but simply more time-consuming (even though I used "Word" to manipulate data so that I didn't have to type each of those entries line by line) that I didn't give a whole lot of attention to my Category::On Element Entry coding. After all, that was fairly straightforward and I've done something similar many times.

[b][i]Yet[/i][/b] that is precisely where my problem was.  The global coding had (as shown above)

Jams, Jellies
Jello, Pudding

[b][i]But[/i][/b] the Category::On Element Entry coding had

Jams Jellies
Jello Pudding

Soooo Sesame did just what it was told - looked up the value of "Jams Jellies" or "Jello Pudding" and couldn't find it.

All I can say, is that I revealed several "pit-falls" in this little exercise and I hope it will prove to be of benefit to someone else.  I am determined to get this working, no matter what!

However, in the meantime, I have decided to add a database to the application and to use that database for the lookup.

Now for a little levity, after this torture,
 
[move][glb] HAPPY[/glb][i]... as you click on the messy looking link  below[/move][/i]

[url]http://www.msn.americangreetings.com/view.pd?i=382219626&m=1652&rr=y&s
[/url]

[move][glb]THANKSGIVING!!![/glb]
[/move]
  

- Spencer

    ** Practice random kindness & senseless acts of beauty!
Back to top
IP Logged