[comp.sys.mac.programmer] Reading Numbers from Modal Dialog Items...PLEASE HELP

isler@grad1.cis.upenn.edu (Sylvia-Kay ISLER) (09/09/90)

I am writing a program in Think C 3.0 that has to obtain floating point values
from modal dialog items. I am running into serious problems.
 I am trying to do so using this code: 

float number;
.
.
.
getparameter(DialogItemNum, &number);
.
.
.
}


getparameter(num, value)

int num;
float *value;

{
	int type;
	Rect box;
	Str255 text;
	Handle item;
	GetDItem(theDialog, num &type, &item, &box);
	GetIText(item,text);
	sscanf(PtoCstr((char *)text), "%3.3f", *&value);
}

the 0.00 always appears in the variable value.

if anyone has code that reads floating point numbers from dialog items,
please help me out.

Sylvia Isler
isler@grad1.cis.upenn.edu

rotberg@dms.UUCP (Ed Rotberg) (09/10/90)

From article <29331@netnews.upenn.edu>, by isler@grad1.cis.upenn.edu (Sylvia-Kay ISLER):
> I am writing a program in Think C 3.0 that has to obtain floating point values
> from modal dialog items. I am running into serious problems.
>  I am trying to do so using this code: 
> 
> getparameter(num, value)
> int num;
> float *value;

lines deleted...

> 	sscanf(PtoCstr((char *)text), "%3.3f", *&value);
					       ^^
I beleive that I have some code at home that gets floating point data from
a dialog, but in the meantime, I think this contruct looks suspect.
Since value is a pointer to a float, just pass value to sscanf.  Also,
I might suggest just using %f instead of %3.3f unless you have a real
reason to limit the field.  The field width specifiers are primarily for
output, especially when one is expecting only one value in the entire
input string ... you are expecting only one value, aren't you?

If this doesn't help, I'll try to dig up that other code...

	- Ed Rotberg -

smoke@well.sf.ca.us (Nicholas Jackiw) (09/26/90)

In article <29331@netnews.upenn.edu> isler@grad1.cis.upenn.edu (Sylvia-Kay ISLER) writes:
>I am writing a program in Think C 3.0 that has to obtain floating point values
>from modal dialog items. I am running into serious problems.
>
>Sylvia Isler
>isler@grad1.cis.upenn.edu

You might want to try using SANE.  It has a call, Str2Num(aStr:Str255) which
takes a pascal string and returns an extended floating point value.  It's very
efficient, and has the advantage of supporting not only a "standard" (so, if
it has meaning in your program, users can easily enter infinity and other
difficult-to-represent numeric notions) but also of being fully script-
manager compatible, so that if a eurouser should separate units from
decimal portion with a comma instead of a period, it won't choke. 

The _Apple Numerics Manual_ is the ostensible source for more info, but
it's not very helpful.  I tend to just browse my SANE headers for the
appropriate declarations and work from there.


-- 
                              --- * ---
Nicholas Jackiw                Smoke@well.sf.ca.us | Jackiw@cs.swarthmore.edu
Key Curriculum Press, Inc.     Applelink: D3970    | (415) 548-2304
                              --- * ---