我正在使用bat文件來處理數據庫,我的變量沒有正確擴展。爲什麼我的變量不能正確擴展
編輯:
我已經嘗試了上述暫時還沒有這樣的運氣。
這是必需的所有節目的代碼:
set n=0
:1
echo.
set /p fname=Enter First Name:
set /p lname=Enter Last Name:
set /p val%n%=Enter E-mail:
set /p num%n%=Enter Phone Number:
set /p var%n%=Enter Service Number:
set /p dvice%n%=Enter Device:
set /p dserv%n%=Enter Date Serviced:
set /p summ%n%=Enter Summary of Service:
@echo set var%n%=!var%n%! > "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
@echo set val%n%=!val%n%! >> "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
@echo set fname=%fname% >> "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
@echo set lname=%lname% >> "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
@echo set dvice%n%=!dvice%n%! >> "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
@echo set dserv%n%=!dserv%n%! >> "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
@echo set summ%n%=!summ%n%! >> "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
@echo set num%n%=!num%n%! >> "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
@echo set n=%n% >> "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
echo.
echo The data has been stored!
echo.
pause > nul
goto start
:2
echo.
echo LAST NAME IS CASE SENSITIVE!
set /p lname=Please enter last name:
echo.
if /i not exist "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat" (goto Error)
call "C:\Documents and Settings\Administrator\Desktop\My Personal Files\Computer Refresh\Database\%lname%.bat"
echo First Name: %fname%
echo Last Name: %lname%
echo Device: !%dvice%%n%!
echo Date of Service: !dserv%n%!
echo.
echo E-Mail: !val%n%!
echo Phone: !num%n%!
echo.
echo Summary:
echo.
echo !summ%n%!
echo.
pause > nul
goto start
這是我所有的工作。 %lname%.bat將變量存儲爲var0 =「變量值」問題在於它不讀取var0。它讀取!var 0 !.
您尚未提供足夠的代碼來診斷問題。也許問題是價值從未設置,否則由於ENDLOCAL或其他類似原因導致值丟失。嘗試不帶參數的'set'來查看所有已定義的變量。 – dbenham
我實際上刪除了代碼,因爲它使帖子冗長。變量設置爲!var%n%!並正確存儲。只是不能被閱讀。 –
我強烈建議您按照我的建議,並在代碼的末尾放置'set'命令(不帶參數)以列出所有當前定義的變量。我相信你會看到你的變量不再被定義。正如Magoo在他的回答中所表明的那樣,問題出現在您未顯示的早期代碼中。 – dbenham