Can't Trap "String Input When a Numeric Value Is Expected" (47754)






This article was previously published under Q47754

SUMMARY

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
				

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB47754