Microsoft KB Archive/47754

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:56, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


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

Article ID: 47754

Article Last Modified on 11/21/2006

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
                


Additional query words: QuickBas BasicCom

Keywords: KB47754