我制作了一个数据库脚本来存储礼品卡代码。但是,在我的脚本中,变量不知何故包含任何东西。当我删除在这个问题中没有关系的东西时,我意识到它有效。
WORKING:
::making variables
@echo off
title Please insert your code here:
cls
set /p code=Please insert your code here:
cls
title Who is the code from?
set /p client=Who is the code from?
cls
title For what did you get the money?
set /p what=For what did you get the money?
cls
title What's the amount of money saved on the code?
set /p amount=What's the amount of money saved on the code?
cls
::write to txt
@echo Code: %code%; Who: %client%; What: %what%; Money [in Euro]:%amount%>> %CD%\assets\database.txt
@echo off
color 0c
@echo Successfully written to database!
pause
exit
不工作:
:PASSWORDPROMPT
@ECHO off
setlocal EnableDelayedExpansion
@echo off
cls
@echo off
title Insert Password:
@echo off
set /p Passwort=Insert your Password here:
if %Passwort%==mypassword goto YES
if not %Passwort%==mypassword goto NO
:YES
if exist %CD%\assets\database.txt (
goto EXISTS
) else (
md %CD%\assets\
copy /b NUL %CD%\assets\database.txt
attrib +h %CD%\assets
)
:EXISTS
@echo off
title ENTER OR READ?
@echo off
cls
set /p readwrite=Do you want to ENTER a code to the database or READ the database? [ENTER/READ]
if /i %readwrite%==ENTER (
@echo off
title Please insert your code here:
cls
set /p code=Please insert your code here:
cls
title Who is the code from?
set /p client=Who is the code from?
cls
title For what did you get the money?
set /p what=For what did you get the money?
cls
title What's the amount of money saved on the code?
set /p amount=What's the amount of money saved on the code?
cls
@echo Code: %code%; Who: %client%; What: %what%; Money [in Euro]:%amount%>> %CD%\assets\database.txt
@echo off
color 0c
@echo Successfully written to database!
@echo off
color 0b
<nul set /p "=Press a key to Close..."
pause >nul
title Closing...
@echo off
for /L %%A in (3,-1,0) do (
cls
echo Closing in %%A Seconds.
ping localhost -n 2 >nul
cls
)
) else (
cls
@echo off
color
cls
@echo off
@echo ________________________________________________________
@echo YOUR CODES:
@echo ________________________________________________________
color
more %CD%\assets\database.txt
@echo ________________________________________________________
<nul set /p "=Press a key to Close..."
pause >nul
)
exit
:NO
cls
color 0c
@echo WRONG PASSWORD!
@echo off
timeout 1 /nobreak >null
@echo off
for /L %%A in (3,-1,0) do (
cls
echo Reload in %%A seconds...
ping localhost -n 2 >nul
)
cls
goto PASSWORDPROMPT
有人知道有什么区别以及如何修复代码吗?
答案 0 :(得分:0)
您遇到了延迟扩展问题。您似乎已经启用了延迟扩展。
但是,为了保持兼容性,我们必须更改要在运行时更新的变量,如下所示:
%var% -> !var!
请注意,它仅适用于某些变量。以下示例无效:!!~A
,!1
根据您的情况,您应该修改您的代码:
@echo Code: !code!; Who: !client!; What: !what!; Money [in Euro]:!amount!>> %CD%\assets\database.txt