only accept numeric data
k, so i have this single line edit box and i want to get data from the user, but i want no alpha data, purely numeric. for some reason, my big long if statement thats supposed to tell if the data is numeric or not - isn't working. idky...its probably a stupid reason, but here's what i'm trying:
it displays every character (saying that no character it has is a number) in a messagebox and then tells me that i only accept numberic data. the data i've tried entering is 212 , thats purely numeric :(
for (i = 0; i <= length; i++)
if (dubbuf[i] < 48 && dubbuf[i] != 46 || dubbuf[i] > 57 || dubbuf[i] != 0)
debug = dubbuf[i];
MessageBox(hwnd, debug, "the culprit..", MB_OK);
go = 0;
is there a better way? what am i doing wrong? :( help :( lol
also, it would be better if i could disallow alpha values while the user is entering data, i'd much rather do it that way then checking after the person pushes a button. can i do this? how pleeeaaase :):) thanks :).
Well the strange mix of && and || in the expression is odd.
And using something like
if (dubbuf[i] < '0'
Would be more readable - what's 46 (without reaching for your ascii table?)
Personally, I'd use say strtol() and see how far it gets through the string.
lol true, 46 is . :) but i only know that b/c i'm using it.
i'll have to read up a lil on strtol, but thanks :)
mm..also, every time i use atof, instead of having 212.000... i get 212000... , i have a double declared for what atof is putting the value into, and for the char it doesn't matter if i put 212 or 212.0, it always does this.
>>single line edit box...i want data, purely numeric<<
Create the edit control with the ES_NUMBER style bit set.
To retrieve the value use GetDlgItemInt.
An EN_CHANGE notification is sent each time a change is made to the edit control's contents.
why thank you :) its beautiful.
if alpha data is entered, GetDlgItemInt returns FALSE and i send a messagebox and do no further processing :) BUT this is doing something really strange. for debugging purposes, i was outputting the calculations the program made to a text file. then when i finally got it to work, ..i just dont understand what happens. like if it does a calculation from fahrenheit to celsius, i have fiveninths declared as a double and set to: 0.5555555555555. so it does input = fiveninths * (input - 32.0); input is also a double. when the calculation is output to the text file, its 100.000000 but when its sent to the screen, SetDlgItemInt(hwnd, ID_LABEL5, input, TRUE); it outputs 99. i tried FALSE for the signed / unsigned bool but that made no difference, still 99. why?? :(
//edit - when having the edit declared with ES_NUMBER, it disallows a decimal point :(
try a cast
also if you need decimals try
isdigit(dubbuf[i]) //tests char is a digit
dubbuf[i] == '.' //tests for asii value of a period
i wasn't using chars anymore as of now but i'm thinking if i need decimals i'm going to have to. even tho GetDlgItemInt is just so much easier, lol *dammit*
but yea - typecasted or not, it still outputs 99 to the screen and 100.000000 to the text file. :( here's my function so far:
void Calculate(HWND hwnd, double input)
fileptr = fopen("output.txt", "wb");
if (fileptr == NULL) MessageBox(hwnd, "there was an error creating the file.",
"error", MB_OK | MB_ICONERROR);
if (type_of_conversion == 1)
input = fiveninths * (input - 32.0);
fprintf(fileptr, "FtoC result: %f\n", input);
SetDlgItemInt(hwnd, ID_LABEL5, (int)input, FALSE);
also - should the last parameter of the SetDlgItemInt be TRUE or FALSE? :) thanks
//edit - this is curious. the fraction 5/9 = .55555... and 9/5 = 1.8000... but when put into the function, produce different results. with the code as it is above, it displays 99 on the screen. but if the math changes to:
input = (input - 32.0) / ninefifths; then the displayed result on the screen is 100.
*doesn't really get it* whatever.
i'm still looking to get decimals because you can't really convert a temperature when the only way to do it is with whole degrees. its just not accurate.