Page 1 of 1

PostPosted: Fri Jun 13, 2003 12:36 pm
by Bob Hall
I am trying to get the list box to return a value that is a #define statement. It only returns the string that appears in the list box.
The code is as follows:

#define Pi 3.141


selection = Cgetcontent(Constants);

The output is the string Pi.
I wamt the output to be the value 3.141.

the following code works

selection = Cgetcontent;
if (selection = Pi)
puts(selection2);(output is 3.141)

while this works it makes for many lines of code when there are many constants in the list.

Is there a better method to get the Cgetcontent to return the value rather than the string.


PostPosted: Sat Jun 14, 2003 7:53 pm
by soinsg
Is selection or selection2 a float?
Code: Select all
puts((float)selection); //Use format() to specifiy decimal places

Code: Select all
if (selection = Pi) //Should be ==
  selection2 = Pi;

But I assume that was just a typo :D.

PostPosted: Mon Jun 16, 2003 3:05 pm
by Bob Hall
Thanks for the reply Soinsg.

I had previously tried casting as a float and that didn't work.

When using Clist you can add to the list box two ways

Cadditme (listbox, "Pi")

which is a string


Cadditem (listbox, Pi)

which will return 3.141 if previously defined but the list box says 3.141.

Looks like I will have to use the if statement solution.

Thanks anyway.

Bob Hall