Qbasicnews.com
Function to validate string for numeric with decimal point - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QbasicNews.Com (http://qbasicnews.com/newforum/forum-3.html)
+--- Forum: Challenges (http://qbasicnews.com/newforum/forum-10.html)
+--- Thread: Function to validate string for numeric with decimal point (/thread-1434.html)

Pages: 1 2 3 4 5 6


Function to validate string for numeric with decimal point - Agamemnus - 07-10-2003

meh, it isn't as efficient as mine.

Besides, error codes are for wimps who don't use 16x800x600 bit resolution where PRINT statements crash the program Smile


Function to validate string for numeric with decimal point - Moneo - 07-10-2003

AGAMEMNUS,

You still haven't fixed your latest posted version.

What do you mean that error codes are for wimps? This may be true if you program is just for fun and never going to be put into production. Put yourself in a user's shoes. He inputs a piece of data and it's rejected with no corresponding error message. How is he supposed to figure out why?

You have to start thinking in terms of "production quality" programs. Let me tell you that more than 50% of the code and effort for applications that interface with users are devoted to security, entitlement, validation, error messages, and error logging.
*****


Function to validate string for numeric with decimal point - Agamemnus - 07-10-2003

I fixed my last version....

What I mean by "Error codes are for wimps" is that if a program were to be using this internally, (not "INPUT userinput$) it would be quite useless to point out the error it made -- better code it so that it doesn't make an error. Smile

For users, an error code is still not justified. A better approach would be to NOT LET the user make an error by making a custom INPUT that only accepts the right stuff. Smile


Function to validate string for numeric with decimal point - Moneo - 07-10-2003

Quote:....A better approach would be to NOT LET the user make an error by making a custom INPUT that only accepts the right stuff. Smile

What do you have in mind by a "custom INPUT" that only accepts thre right stuff? Give me an example.
*****


Function to validate string for numeric with decimal point - Agamemnus - 07-11-2003

well, I won't code it here since it's a pain, but the general idea is:
Code:
DO
IF instr$(chr$(13)+chr$(8)+"1234567890."), i$) <> 0 then..
end if
LOOP



Function to validate string for numeric with decimal point - Moneo - 07-11-2003

AGAMEMNUS:
Looks like you're doing a kind of character checking. Which brings us back to the subject of having to send the user an error message if he types an invalid charcater. That's what the original routine was all about.
*****


Function to validate string for numeric with decimal point - Agamemnus - 07-11-2003

nay, the user can't enter an incorrect character.


Function to validate string for numeric with decimal point - Moneo - 07-11-2003

AGA,
How do you inhibit the user from entering invalid data? I don't get it.
*****


Function to validate string for numeric with decimal point - Agamemnus - 07-11-2003

when the user presses any number except "0 1 2 3 4 5 6 7 8 9 . backspace" in the input field, just ignore that in your input function. After the user presses ".", ignore "." afterwards, as well. If nothing is entered after ".", then remove the ".".


Function to validate string for numeric with decimal point - Moneo - 07-11-2003

AGAMEMNUS:

That's a wonderful idea you have, but how do you control what keys the user can hit? You cant by using any of the INPUT or INKEY$ commnds that I know? Please tell me how?
*****