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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi Olaf, I tried to add a label, I

Status
Not open for further replies.

ahmed1973

Programmer
Jan 29, 2013
42
DZ
Hi Olaf,
I tried to add a label, It has worked very good,Thank you, but if i'd like to do it in a boucle FOR,
for instance , I recreate this label 5 times one under the other like this:
label1
lebel2
label3
label4
label5

 
If you want to display list of things, use a control, which can display lists of records. Combobox, Listbox, Grid. Use one label as header. or the header in the grid.

Don't go that route of adding a variable number of controls and labels.

Bye, Olaf.
 
we have talked about this problem before, if i use combobox or listbox, I can't sum these amounts .
so i plan to do with these labels is to display them and replace them with these amounts.and then when I click on a label it will added to the previous.for instance
label1=96.30
label2=150.00
...
...
...
text1=label1+label2+label3+.....
 
we have talked about this problem before, if i use combobox or listbox, I can't sum these amounts .

Yes, you can:

Code:
lnTotal = 0
FOR lnI = 1 TO thisform.List1.ListCount
  lnTotal = lnTotal + thisform.List1.List(lnI)
ENDFOR

thisform.TotalLabel.Caption = TRANSFORM(lnTotal)

The big advantage of using a listbbox, grid, etc, is that it can easily deal with a variable number of items in a controlled space. If you add individual labels to your form, you have to worry about how much space they take up, plus it's harder to write any kind of code that loops through them.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Yes, like Mike says,

Using a list control you only need one additional Label and textbox to display the total.
Also you can't calculate with label captions. What you plan to do introiduces more problems than it solves.

Bye, Olaf.
 
hi, my goal is :I click on one amount choosen it will deplace to a text for instance and for each choice it will added automatically IN the text. amount+amount until the end
 
You can do that with any suitable control, including a listbox or grid. It's no reason to use labels.

By the way, I suggest you also provide an Undo feature, to deal with cases where the user clicks on a control by accident.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
You will have a cursor with one record for each amount. You init the cursor by CREATE CURSOR curAmounts ( yAmount Y) (eg you do that in form.load() event). You need to have a listbox and set it's Controlsource to "curAmounts". You need to have a textbox for the total named "TextboxTotal" and init it's Value with $0.00.

When you add an amount, you INSERT INTO cursorAmounts Values (newamount), you also add the new amount to the total in one textbox via TextboxTotal.Value = TextboxTotal.Value + newamount. Then just Refresh it via Thisform.Refresh().

The value newamount needs to be a numeric value, wherever that comes from. The cursor field type Y means it's a currencY field, so that is there to store prices or other monetary amounts, but you can also add "normal" numeric values to it, eg 1.00, all numeric values are taken as currency. The currency symbol can be set via SET CURRENCY TO '€ ' for example for Euro, or 'EUR ', whatever your currency is. And that's it.

Bye, Olaf.
 
You may also read some of hogan19's questions in the MSDN forums, eg starting with this one:
You're not the only one creating a POS system, actually I think you could buy one of rather many POS systems based on Foxpro, you don' have to reinvent the wheel.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top