您有
set tableauNoCamion[%index%]=!input!
echo You entered !tableauNoCamion[%index%]!
爲%index%
將與index
內容在當時的for ...%%f
是解析
不要index
都懶得進行評估的一個主要問題;使用
set tableauNoCamion[%%f]=!input!
echo You entered !tableauNoCamion[%%f]!
至於第二個循環中,你可以使用
set tableauNoCamion
或
for /f "tokens=1*delims==" %%a in ('set tableauNoCamion') do echo %%a
或
setlocal enabledelayedexpansion
for /L %%a in (1,1,%nombreDeCamion%) do echo !tableauNoCamion[%%a]!
endlocal
(所有的空氣碼 - 未經)
還有其他 - 取決於你想要的報告。
對於任何你想要做的*.jpg
或不可─*.jpg
文件 - 這是一個謎,我...
嗯,是的 - 問題是,任何改變的環境做出在達到匹配的endlocal
時setlocal
撤消後。
熙的修訂......
@echo off
setlocal EnableDelayedExpansion
SET /P input1=Nombre de camion :
set nombreDeCamion=%input1%
for /l %%f in (1,1,%nombreDeCamion%) DO (
set index=%%f
SET /P input=Entrer le no du camion:
set tableauNoCamion[%%f]=!input!
echo You entered !tableauNoCamion[%%f]!
)
echo===============
SET tableaunocamion
echo===============
for /L %%a in (1,1,%nombreDeCamion%) do echo !tableauNoCamion[%%a]!
echo===============
for /f "tokens=2,3delims=[]=" %%a in ('SET tableaunocamion') do echo %%a. %%b
GOTO :EOF
注:爲cmd
會話中運行的代碼我。如果您從「快捷方式」運行,則需要在戰略上插入pause
。
這裏有一個樣品的結果:(進入4,11,22,33,44)
Nombre de camion : Entrer le no du camion: You entered 11
Entrer le no du camion: You entered 22
Entrer le no du camion: You entered 33
Entrer le no du camion: You entered 44
==============
tableauNoCamion[1]=11
tableauNoCamion[2]=22
tableauNoCamion[3]=33
tableauNoCamion[4]=44
==============
11
22
33
44
==============
1. 11
2. 22
3. 33
4. 44
脫線喜, 我想你的解決方案,爲第二循環,但遺憾的是,前兩個給了我這個錯誤。環境變量tableauNoCamion未定義。 第三個給我的錯誤回聲命令被停用 – N3M0QC 2014-09-27 13:52:46