除了一秒钟之外,我无法看到错误,但是有人可以在此代码中找到错误或拼写错误吗?
GOTO MAIN
REM Put this anywhere in the code, to call the generated character, use %CHA%, to generate a new one, use GOTO RAND.
:RAND
PING -w 62.5 1.1.1.1 > NUL
SET /A RAN=(%RANDOM%*100) / 32768
IF %RAN% GEQ 1 (
GOTO CHEC
) ELSE (
GOTO RAND
)
:CHEC
IF %RAN% LEQ 36 (
GOTO VALI
) ELSE (
GOTO RAND
)
:VALI
SET VAL=%RAN%
)
IF %VAL%=1 (
SET CHA=A
) ELSE (
GOTO 0002
)
:0002
IF %VAL%=2 (
SET CHA=B
) ELSE (
GOTO 0003
)
:0003
IF %VAL%=3 (
SET CHA=C
) ELSE (
GOTO 0004
)
:0004
IF %VAL%=4 (
SET CHA=D
) ELSE (
GOTO 0005
:0005
IF %VAL%=5 (
SET CHA=E
) ELSE (
GOTO 0006
)
:0006
IF %VAL%=6 (
SET CHA=F
) ELSE (
GOTO 0007
)
:0007
IF %VAL%=7 (
SET CHA=G
) ELSE (
GOTO 0008
)
:0008
IF %VAL%=8 (
SET CHA=H
) ELSE (
GOTO 0009
)
:0009
IF %VAL%=9 (
SET CHA=I
) ELSE (
GOTO 0010
)
:0010
IF %VAL%=10 (
SET CHA=J
) ELSE (
GOTO 0011
)
:0011
IF %VAL%=11 (
SET CHA=K
) ELSE (
GOTO 0012
)
:0012
IF %VAL%=12 (
SET CHA=L
) ELSE (
GOTO 0013
)
:0013
IF %VAL%=13 (
SET CHA=M
) ELSE (
GOTO 0014
)
:0014
IF %VAL%=14 (
SET CHA=N
) ELSE (
GOTO 0015
)
:0015
IF %VAL%=15 (
SET CHA=O
) ELSE (
GOTO 0016
)
:0016
IF %VAL%=16 (
SET CHA=P
) ELSE (
GOTO 0017
)
:0017
IF %VAL%=17 (
SET CHA=Q
) ELSE (
GOTO 0018
)
:0018
IF %VAL%=18 (
SET CHA=R
) ELSE (
GOTO 0019
)
:0019
IF %VAL%=19 (
SET CHA=S
) ELSE (
GOTO 0020
)
:0020
IF %VAL%=20 (
SET CHA=T
) ELSE (
GOTO 0021
)
:0021
IF %VAL%=21 (
SET CHA=U
) ELSE (
GOTO 0022
)
:0022
IF %VAL%=22 (
SET CHA=V
) ELSE (
GOTO 0023
)
:0023
IF %VAL%=23 (
SET CHA=W
) ELSE (
GOTO 0024
)
:0024
IF %VAL%=24 (
SET CHA=X
) ELSE (
GOTO 0025
)
:0025
IF %VAL%=25 (
SET CHA=Y
) ELSE (
GOTO 0026
)
:0026
IF %VAL%=26 (
SET CHA=Z
) ELSE (
GOTO 0027
)
:0027
IF %VAL%=27 (
SET CHA=0
) ELSE (
GOTO 0028
)
:0028
IF %VAL%=28 (
SET CHA=1
) ELSE (
GOTO 0029
)
:0029
IF %VAL%=29 (
SET CHA=2
) ELSE (
GOTO 0030
)
:0030
IF %VAL%=30 (
SET CHA=3
) ELSE (
GOTO 0031
)
:0031
IF %VAL%=31 (
SET CHA=4
) ELSE (
GOTO 0032
)
:0032
IF %VAL%=32 (
SET CHA=5
) ELSE (
GOTO 0033
)
:0033
IF %VAL%=33 (
SET CHA=6
) ELSE (
GOTO 0034
)
:0034
IF %VAL%=34 (
SET CHA=7
) ELSE (
GOTO 0035
)
:0035
IF %VAL%=35 (
SET CHA=8
)ELSE(
SET CHA=9
)
REM The GOTO 00XX is not necessary, but, if you modify the RAN, VAL, or CHA variables outside of this "block," you are able to "double check" a number.
:MAIN
答案 0 :(得分:0)
您的脚本存在的问题是您使用单个=
进行比较,而您应使用双==
。
IF %VAL%=1 (
:: Should Be
IF %VAL%==1 (
:: Or
IF %VAL% equ 1 (
但是,我建议尝试这样的事情。
@echo off
setlocal EnableExtensions
:: Example Usage
call :RAND CHA
echo %CHA%
endlocal
pause >nul
exit /b
:RAND <Result>
setlocal EnableExtensions EnableDelayedExpansion
set "A=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
set /a "X=%RANDOM% %% 36"
:: Without Delayed Expansion
::call set "C=%%A:~%X%,1%%"
:: With Delayed Expansion
set "C=!A:~%X%,1!"
endlocal & set %~1=%C%
exit /b