Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Problem

Status
Not open for further replies.

MichaelM99

Programmer
Oct 22, 2017
2
NI
Hi -
Two months ago, I returned to VFP after a 25 year absence from any programming other than the occasional website. It has, in the main, been a very pleasant culture shock and I am really glad that, despite Microsoft, the VFP community is still so strong. I am older but sadly not wiser - hence my appearance here.
I am working on a project for a small restaurant a friend is opening here in Nicaragua (I originate from London, England - another culture shock!). It has been a steep relearning curve but my old passion has returned! I am using VFP9 - I can't remember what it was when I last used it but much came back to me very quickly although I made a classic data normalisation mistake for recipes where I have fields for ingredient1, ingredient2 up to ingredient15.
Available ingredients are shown in a style=2 combo - one for each of the (up to) 15 ingredients. This is repeated for ingredient units. That is all working fine but bad design.
I am now working on the drinks side but want to design it properly but I am getting into a real mess with mixed drinks which are basically recipes.
I have 3 tables, one with just 2 fields, Drinks - DrinkID and DrinkName.
Then a table with 3 fields, Items - DrinkID, ItemID and Quantity (there will doubtless be others).
Lastly, I am using the recipes ingredient table with a logical field Drink from which I select the available drink ingredients - it made sense to me to use that table as all stock movements are recorded there so makes reporting easier. The relevant fields are ItemID, ItemName. It also has a UnitID linking to a Units table but that is not really relevant here.
Unlike my earlier mess, I just want to show combos under each other with a line for each item with a button to add a new line for a new item. This I am trying to do with AddObject.
The relevant bits of code are:
First, COUNT FOR DrinkItems.DrinkMadeID = Drinks.DrinkMadeID TO Thisform.ItemLines && get number of items
Then SQL - SELECT ingredie
SELECT Ingredie.Ingred_id, Ingredie.ingredient, Ingredie.drinkshow ;
FROM ;
RECIPES!INGREDIE ;
WHERE Ingredie.drink = .t. ;
ORDER BY Ingredie.ingredient ;
INTO CURSOR curIngred
This is the list I want in each combo obviously displaying the previously chosen one.
Then I am calling a method, AddItemLines as many times as there are ItemLines.
This method has had many different shapes over the past few days but none have worked - the combos are usually greyed out or empty. I have had it working with one iteration of AddItemLines but that is not very useful. This is the current incarnation:
LOCAL lnWorkArea
lnWorkArea = SELECT()
SELECT DrinkItems
n=ALLTRIM(STR(thisform.combonext))
thisform.AddObject('Combo&n','Combobox')
WITH thisform.Combo&n
.BoundColumn = 2
.BoundTo = .t.
.ControlSource = Ingredie.Ingredient && not sure whether quotes are necessary
.DisplayCount = 0
.FirstElement = 1
.RowSource = "curIngred.Ingredient, Ingred_ID"
.RowSourceType = 5
.height = 24
.left = 80
.style = 2
.top = thisform.ctop
.width = 200
.visible = .t.
.enabled = .t.
ENDWITH
thisform.AddObject('ntxtBox&n', 'TextBox')
WITH thisform.ntxtBox&n
.ControlSource = DrinkItems.Quantity
.top = thisform.ctop
.width = 25
.left = 283
.InputMask = "99"
.value = 1
. visible = .t.
ENDWITH
SKIP
thisform.combonext = thisform.ComboNext + 1
thisform.cTtop = thisform.cTop + 27
SELECT(lnWorkArea)

I am sure that there is something fundamentally wrong with my thinking but I am now at the point of despair! I have tried array as I think there is a problem with the Items record pointer have to move with each new row. I just cannot now see the wood from the trees. I know there is some inconsistency between field names but they are consistent in my code.
Any help pointing me in the right direction would be very much appreciated. I have followed this formum for a while and am amazed at the quality of the members, present company excepted! I have already learned so much.

Michael

 
Hi Michael,

what I'm missing in your code is the REQUERY of your combos. Combos have to be REQUERIED so they can reread the current array/List/Cursor whatever correctly. A simple REFRESH isn't enough. So, you can requery after each AddItem or after the list is completed. Requery at the end of the loop will be faster though. So just place a

Code:
.Requery

in your code as soon as all items have been added.

An additional attempt is, to create a subclassed combobox/textbox that have all properties set in just the way you need/want it and instead of

Code:
thisform.AddObject('Combo&n','Combobox')

you set the classlib that contains combo and textbox at programstart.

Code:
SET CLASSLIB TO myClasses

Assuming you called the combo 'myCombo' and the textbox 'myText' you would add them like this:

Code:
thisform.AddObject('Combo&n','myCombo')
thisform.AddObject('Combo&n','myText')

HTH

-Tom
 
Hi Tom -

Thanks for your advice - much appreciated. I shall do what you suggest and let you know. I didn't think of subclassing but that makes a lot of sense and makes life easier. I wish I had subclassed the form at the start of the project - I only did that last week.

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top