KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q47754: Can’t Trap "String Input When a Numeric Value Is Expected"

Article: Q47754
Product(s): See article
Version(s): 4.00 4.00b 4.50
Operating System(s): MS-DOS
Keyword(s): ENDUSER | docerr B_BasicCom SR# S890711-21 | mspl13_basic
Last Modified: 18-DEC-1989

The documentation incorrectly states that you can "...safeguard your
program from user errors such as string input when a numeric value is
expected..." in the following manuals:

1. "Microsoft QuickBASIC 4.0: Programming in BASIC: Selected Topics"
   manual for Versions 4.00 and 4.00b, Page 279

2. "Microsoft QuickBASIC 4.5: Programming in BASIC" manual for Version
   4.50, Page 225

3. "Microsoft BASIC Compiler 6.0: Programming in BASIC: Selected
   Topics" for Microsoft BASIC Compiler Versions 6.00 and 6.00b, Page
   279

This documentation error is not present in Microsoft BASIC PDS Version
7.00.

It is not possible to use the ON ERROR GOTO statement to trap the
"Redo from Start" error that occurs for the INPUT statement when a
string is entered and a numeric value is required. To avoid the "Redo
from Start" error message, you must use a different form of input,
such as the LINE INPUT statement or the INKEY$ function.

Because LINE INPUT accepts all characters until it encounters a
carriage return, you must parse the input string yourself using string
manipulation (e.g. MID$, INSTR) and type conversion (e.g. VAL).

For a code example of a line-input routine using the INKEY$ statement,
query on the following words:

   INKEY$ and CTRL+BREAK and DEBUG and GOSUB

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.