CompuServe Thread

#Dialog help

2 messages in this thread
#131925From: Gary KratzerJul 15, 1993 2:20 PM
I've got a dialog box that contains several edit text items and I need help with a couple of problems. BTW – I'm using THINK C 5.0. 1) How can I restrict the number and type of characters the user can enter in each item? (I only want to accept numbers, commas and periods.) 2) After I get the data from the item using GetIText I need to perform several calculations. How do I convert a Str255 to/from a double? Thanks, Gary
#132432From: C.K. HaunJul 19, 1993 11:00 PM
Gary, You can do edit line length restriction either in a modal dialog filter or when ModalDialog returns a hit in the edit line. In the filter is cleaner since the extra character never actually shows up, you can look at the example DialogBits 2.0.1 on a developer CD if you have access to one. It's a little long to put in here, and anyway I _again_ don't have my CD drive turned on, you'd think I'd learn….. If you want to do it after the return from ModalDialog, just add something like this….. ModalDialog(nil,&hititem); if (hititem == kMyEditLine) { GetDItem(myDialog, kMyEditLine, &itemType, &itemhandle, &itemRect); GetIText(itemhandle, &tempString); /* don't want them to go over 20 characters */ if (tempString[0] > 20) { SysBeep(1); /* yell */ tempString[0] = 20; /* reset len to 20 */ SetIText(itemhandle, &tempString); /* reset edit line } As for converting from text to a double, there isn't a toolbox function to do this. I would say a creative use of the C StdLib function sprintf(…) would work, that's the way I usta do it on IBMs. Or, you could just walk the resulting character string (from GetIText) looking for the '.' and hand-make a double. Someone else hasd got to have a better idea…. CKH