Re: CComboBox-Droplist: float values?




"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:rs69j31sgtil8d5pevn6gsr8et0ul0hkk3@xxxxxxxxxx
Which works fine if you believe that the only values you will have are the
ones given, and
the combo box is unsorted. I learned years ago to NEVER depend on the
index of a combo
box or list box EXCEPT to retrieve the value I want. This makes the code
robust-under-maintenance, a critical factor in what I build (code I write
will always be
maintained by unskilled labor, which means either the new hire or myself
six months later)
joe


I don't disagree. a) there really is this small number of values to choose
from and b) my approach to get a functional proof-of-concept, then optimize
based on what I've learned about the problem during the proof-of-concept
build.



On Fri, 9 Nov 2007 10:32:20 -0600, "BobF" <rNfOrSePeAzMe@xxxxxxxxxxx>
wrote:


"BobF" <rNfOrSePeAzMe@xxxxxxxxxxx> wrote in message
news:Or7iQquIIHA.3848@xxxxxxxxxxxxxxxxxxxxxxx

"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:%23LNB7luIIHA.5328@xxxxxxxxxxxxxxxxxxxxxxx
Joseph M. Newcomer wrote:
(a) format the float value as a string
(b) add the string to the combo box

Now, if it is a *sorted* combo box, you have the classic "numeric
sort"
problem. If you
are using 'float', it is fairly easy; you create an owner-draw combo
box
without
LBS_HASSTRINGS and implement CompareItem. Store the float in the
itemData part. There is
a trick, however: you can't cast a float to an LPARAM without causing
it
to be converted
to an integer, so the trick is to do the following:

Joe:

Why not just use atof() on the strings and compare the results?


David, I've been down that road. For some reason, GetWindowTextW
returns
only the '.' of strings formatted similarly to "0.25". Obviously not
enough for atof to work with :-((

an even easier way:

.
.
.
int i = comboboxcvar.GetCurSel();
switch (i)
{
case 0: SetDuration(0.25);
break;
case 1: SetDuration(0.5);
break;
case 2: SetDuration(1.0);
break;
case 3: SetDuration(5.0);
break;
case 4: SetDuration(10.0);
.
.
.

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


.



Relevant Pages

  • Re: CComboBox-Droplist: float values?
    ... Store the float in the ... a trick, however: you can't cast a float to an LPARAM without causing it ... Why not just use atof() on the strings and compare the results? ...
    (microsoft.public.vc.mfc)
  • Re: CComboBox-Droplist: float values?
    ... Store the float in the ... a trick, however: you can't cast a float to an LPARAM without causing it ... Why not just use atof() on the strings and compare the results? ...
    (microsoft.public.vc.mfc)
  • Re: CComboBox-Droplist: float values?
    ... Store the float in the ... a trick, however: you can't cast a float to an LPARAM without causing it ... Why not just use atof() on the strings and compare the results? ...
    (microsoft.public.vc.mfc)
  • Re: inconsistent behavior of >FLOAT
    ... he has to implement the checker by himself; ... checks the syntax exactly (and without blanks or empty strings). ... The intent of>FLOAT is to do its best to convert anything even remotely convertible. ...
    (comp.lang.forth)
  • Re: a few thoughts for ruby...
    ... I'm not in favour, for Robert Klemme's reasons. ... to normally use strings to get BigDecimal values to avoid precision errors. ... so I'd agree that encouraging Float -> BigDecimal conversions ...
    (comp.lang.ruby)