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, I have a textbox and combobox,

Status
Not open for further replies.

ahmed1973

Programmer
Jan 29, 2013
42
DZ
Hi,
I have a textbox and combobox, I d like to affect the value of this combo that contains numbers to the textbox.my goal is to : when i valid I affect the sum to the textbox.
 
In valid do:

thisform.text1.value = thisform.text1.value + this.value

You need to change text1 to whatever the rel name of the textbox.
You might need to convert this.value to numeric type, if the combobox items are texts, then add VAL(this.value)

Bye, Olaf.
 
hi olaf
yes , that what i have done, i've written the same code, but i had the first value selected and then iwhen i select the second value it wil not added to the first vealue.
 
i mean i can't have the sum of each selection.i want when i select a number from the combobox it will added to the value stored in the textbox .

 
<< .i want when i select a number from the combobox it will added to the value stored in the textbox >>

I think Olaf has given you that.

To recap, if the text box is Text1, and the combo box is Combo1, then the code you want is:

Code:
THISFORM.Text1.Value = THISFORM.Text1.Value + THISFORM.Combo1.Value

This assumes that all the values are numeric. If the combo values are strings, do this instead:

Code:
THISFORM.Text1.Value = THISFORM.Text1.Value + VAL(THISFORM.Combo1.Value)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
sorry but it doesn't work, the textbox the first value selected but it doesn't add the second value etc...
 
Are you perhaps referring to a combobox only? The upper part of it looking like a textbox, is part of the combobox. It's there to display the last selection or a preselection. It's not a textbox. The user interface you intend to do is not at all regular, even if we talk about a textbox and a combobox. It would perhaps help to show a screenshot of what you have and/or what you intend.

Bye, Olaf.
 
i have written the code in VALID event
THISFORM.Text9.Value = THISFORM.Text9.Value + THISFORM.Combo1.Value
 
OK,

Sorry, my Crystal Ball is at a cleaner.

Questions:
1. Did you write this in the VALID event of the combo1 box?
2. Did you also tried VAL(THISFORM.Combo1.Value) ? (because you can't add a string to a number, that gives a type error)
3. Do you init Text9.Value with 0? (because you also can't add a number to a string, also an empty string, that also gives a type error)
4. Do you get any error?
5. If you get an error, what?
6. Would it perhaps help to use the Combo1 InteractiveChange event instead of Valid? To explain: Valid only runs, if you leave the combobox, Interactivechange runs after each selection is made, even before you tab away or click into another control. It's not clear if you actally don't want this only to happen when valid happens, but you initially gave that as the outset. Maybe you don't have a clue, it's the wrong event, though.

Bye, Olaf.
 
Olaf said:
Would it perhaps help to use the Combo1 InteractiveChange event instead of Valid?

Wouldn't that cause the value to be added at every keystroke? So, if the textbox values starts at 1, and the first three combo values were 1, 2, and 3, then if the user hits the down-arrow key in the combo, the text box would be 2 (1 plus the first value); if they hit the key again it would be 4 (2 plus the second value); and if again than 7 (4 plus third value).

I haven't tested that, but if I'm right, maybe it would be better to use the LostFocus?

But, in any case, Olaf is right: we need more information before giving a solution.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
hi,
it works with InteractiveChange, but always a problem what is it ? when the number is repeated in the combo it will not added when i change the number it will. exemple
the combo value 1
1
1
1
2
2
2
here the sum of the first 1 and the first 2.
 
Well, interactivechange also only happens, if you change selection. We come back to what I said about the bad concept, this is not a good way of user interface. Add a buttongroup and put the amounts on them and then make each click add the amount you put on the button caption, that would be more like what I'd expect from eg a POS system.

There is no event, which happens, when you pick the same item again, I think. Maybe the UpClick would do that.

Bye, Olaf.
 
Add a buttongroup and put the amounts on them and then make each click add the amount you put on the button caption, that would be more like what I'd expect from eg a POS system.

Yes, that would be a better interface. I would also add an Undo button, in case they make a mistake.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
i return to my problem, because really i d like to find why it is not working?
when i was trying i have remarked the the values of the combo or the listbox are displaying in the textbox like a value one near the other exemple: the first amount 96.30 then the second 96.30 the third 129.30 like i have done copy from the combo and paste in the text. Is there any solution?
 
Whaat you did when you copy one value instead of adding a value worked in the same, you just didn't ever discover that the reselection of the same value did nothing to the destination textbox value. Because even if a valid or interactivechange would have happend, nothing would have changed in the textbox.

So if you did as you did with the sum of values, and picked
1
1
1
2
2
2
The destionation textbox showed 1,1,1 and then 2,2,2, didn't it? And you were satisfied, because it did, what you want. But in reality, most probably only the first pick of a 1 and the first pick of a 2 changed the textbox. So you think you already got a solution, while there isn't. You can verify that, if you like, by logging what really happens, if you not only change textbox.value but also write out a log file via STRTOFILE() for example. Then you can verify, if your orignal code really happened 6 times and not only twice. If it would really work that way, then you have your solution.

In short, you can continue to insist on knowing a higher truth, or you can take an advice.

Bye, Olaf.
 
i think you have to use the add statement in the combo1.click()event.
 
NasibKalsi,

the idea is not bad and it almost works. It's just a click on the combobox without selecting anything does also add the currently selected value. But it's not bad, in contrast, Upclick does not work at all.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top