Hi!
I am a newbie in bach programming, and I’m having some truble programming questions and answers into a batch file.
My platform is a 486 with ms-dos 4.01
Example:
@echo off
cls
:quest
echo.
echo.
echo What is the name of our country?
echo (Type your answer and press enter.)
if “usa” goto correct
if “unated states of america” goto correct
if error\incorrect goto quest
:correct
cls
echo Congratulations! You won!
goto end
:end
eh.. wel, my knowledge is limited.
I do however hope to be filled in on the “need to know” in order to make this batch work! 🙂 thanks!
Christian P., norway.
i know this thread is older than creation, but i was experimenting and remembered your post…
@goto aaa
e100 B4 01 CD 21 2C 30 48 4C CD 21
RCX
10
W
Q
:AAA
IF EXIST KEY.COM GOTO :BBB
DEBUG KEY.COM < %0.BAT > NUL 2>NUL
:BBB
::Demonstrates capturing of errorlevel to a printable character…
:Captures everything except:<>= key.com subt.s 48 from the input
:does NOT handle backspace – it can be tested for (216), but not handled
:as a rub-out. User would have to retype from start.
@echo off
set E1=!,#,$,%%,&,’,(,+,-,/
SET NUMS=0,1,2,3,4,5,6,7,8,9
set E2=:,;,@
SET CAPS=A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
set E3=[,],^,_,`
SET SMALLS=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
SET E4={,},~
SET TEXT=
:00
SET TEST=
KEY
:: the “reserved words” (ie: not processable due to shell interpretation)
IF ERRORLEVEL 221 IF NOT ERRORLEVEL 222 GOTO :DONE
IF ERRORLEVEL 254 SET TEST=.
IF ERRORLEVEL 216 IF NOT ERRORLEVEL 217 GOTO :BKSPC
IF ERRORLEVEL 252 IF NOT ERRORLEVEL 253 SET TEST=,
IF ERRORLEVEL 250 IF NOT ERRORLEVEL 251 SET TEST=*
IF ERRORLEVEL 249 IF NOT ERRORLEVEL 250 SET TEST=)
IF ERRORLEVEL 242 IF NOT ERRORLEVEL 243 SET TEST=”
:space at end of this line!
IF ERRORLEVEL 240 IF NOT ERRORLEVEL 241 SET TEST=
IF ERRORLEVEL 44 IF NOT ERRORLEVEL 45 SET TEST=\
IF ERRORLEVEL 15 IF NOT ERRORLEVEL 16 SET TEST=?
:these can’t be handled using SET due to conflicts of interest
:IF ERRORLEVEL 14 IF NOT ERRORLEVEL 15 SET TEST=>
:IF ERRORLEVEL 13 IF NOT ERRORLEVEL 14 SET TEST==
:IF ERRORLEVEL 12 IF NOT ERRORLEVEL 13 SET TEST=<
IF ERRORLEVEL 11 IF NOT ERRORLEVEL 12 SET TEST=;
IF NOT “%TEST%”==”” GOTO :XIT
FOR %%A IN (%E3%,%SMALLS%,%E4%,%E1%) DO IF ERRORLEVEL %%A SET TEST=%%A
IF NOT “%TEST%”==”” GOTO :XIT
FOR %%A IN (%NUMS%,%E2%,%CAPS%) DO IF ERRORLEVEL %%A SET TEST=%%A
:XIT
SET TEXT=%TEXT%%TEST%
GOTO :00
:BKSPC
CLS
ECHO SORRY YOU WILL HAVE TO REENTER FROM SCRATCH
SET TEXT=
GOTO :00
:DONE
to use the script (demo):
echo enter some stuff but not grtrthan, lssthan, or equals!
call gettext
echo here’s your text:[%text%]
does not work right on XP and up, but why would you want to anyhows?