Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for usrinp2.bat

(view source code of usrinp2.bat as plain text)

  1. @ECHO OFF
  2. REM * Asks for USeR INPut and store it in variable USRINPUT
  3. REM * Uses ANSI if available, but works without ANSI too
  4. REM * Assumes MS-DOS 6 or later
  5. REM * Written by Rob van der Woude
  6.  
  7. SET USRINPUT=
  8.  
  9. REM * Check if ANSI sequences can be used (needs at
  10. REM * least MS-DOS 6 to get an errorlevel from FIND):
  11. SET ANSI=1
  12. MEM /C | FIND "ANSI" > NUL
  13. IF ERRORLEVEL 1 SET ANSI=0
  14.  
  15. REM * Turn on ANSI key translation (translate Enter
  16. REM * key to F6 + Enter sequence) if possible:
  17. IF "%ANSI%"=="1" ECHO 
  18.  
  19. REM * Ask for input:
  20. IF "%ANSI%"=="0" ECHO Enter one word only, and press F6 followed by Enter . . .
  21. IF "%ANSI%"=="1" ECHO Enter one word only, and press Enter . . .
  22.  
  23. REM * Copy entered text to temporary file:
  24. COPY CON %TEMP%.\~USRINP.TMP
  25.  
  26. REM * Turn off ANSI key translation and clear irrelevant screen output:
  27. IF "%ANSI%"=="0" CLS
  28. IF "%ANSI%"=="1" ECHO 
  29.  
  30. REM * Add empty line to temporary file. The empty line
  31. REM * will be used to stop DATE asking for new date.
  32. ECHO.>> %TEMP%.\~USRINP.TMP
  33. ECHO.>> %TEMP%.\~USRINP.TMP
  34.  
  35. REM * Create a temporary batch file that will store the
  36. REM * entered text into the environment variable USRINPUT:
  37. TYPE %TEMP%.\~USRINP.TMP | DATE | FIND "):" > %TEMP%.\~USRINP.BAT
  38.  
  39. REM * Create more temporary batch files. Add
  40. REM * more command line parameters if necessary,
  41. REM * as in: ECHO SET USRINPUT=%%3 %%4 %%5 %%6 %%7 %%8 %%9>CURRENT.BAT
  42. ECHO SET USRINPUT=%%3>CURRENT.BAT
  43.  
  44. REM * VOER.BAT and TYP.BAT are replacements for CURRENT.BAT for Dutch
  45. REM * DOS versions; add your own language versions if necessary:
  46. ECHO SET USRINPUT=%%6>VOER.BAT
  47. ECHO SET USRINPUT=%%4>TYP.BAT
  48.  
  49. REM * This temporary batch file now sets the variable USRINPUT:
  50. CALL %TEMP%.\~USRINP.BAT
  51.  
  52. REM * Display the result:
  53. IF "%ANSI%"=="0" ECHO You typed: %USRINPUT%
  54. IF "%ANSI%"=="1" ECHO You typed: %USRINPUT%
  55. ECHO.
  56. PAUSE
  57.  
  58. REM * Finally, clean up the mess of temporary files:
  59. FOR %%A IN (%TEMP%.\~USRINP.BAT %TEMP%.\~USRINP.TMP VOER.BAT TYP.BAT CURRENT.BAT) DO DEL %%A
  60. SET ANSI=
  61.  

page last modified: 2024-02-26; loaded in 0.0242 seconds