簡體   English   中英

變量批次內的變量

[英]Variable inside of a variable batch

我做了這個代碼

@echo off & SETLOCAL EnableDelayedExpansion
title TXTanimation
set dir101=C:\USers\%username%\Desktop\file.bat
goto label1
echo Lets make a text animation
pause
set /p dir101=where will the .bat be saved:
:label1
echo @ECHO OFF > %dir101%
echo: >> %dir101%
:menu
echo 0=Edit important information
echo 1=Display .txt
echo 2=Play sound
echo 3=Close sound player
echo 4=Add nessicary wait between .txt
echo 5=Label point
echo 6=Edit variable
    echo 7=Goto point
echo 8=Create IF sentence
echo 9=End it
    echo Add - to the front to view it's guide!    
    Set /p choose=which one:

If '%choose%'=='0' (
SEt /p title=What is the title
:LOL101
set /p color=what color do you want type test to experiment with the colors
If '!color!'=='test' goto tester
goto model
:tester
SEt /p test=Please give hexadecimal number type exit to leave:
if '!test!'=='exit' goto LOL101
color !test!
goto tester
:model
echo title %title% >> %dir101%
echo color %color% >> %dir101%
goto menu
)

If '%choose%'=='-0' (
echo The title is on the top of the screen. The color of the text and backround is a hexadecimal number its 

01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F,10,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20,21,23,24,25...FB,FC,FD,FE. There really are 

values with the same character but those are not valid colors in batch.
goto menu
)
If '%choose%'=='1' (
set /p dir=what is the dir of your .txt:
echo cls >> %dir101%
echo type %dir% >> %dir101%
goto menu
)
If '%choose%'=='-1' (
echo These pictures are what will be shown in the animation.
goto menu
)
If '%choose%'=='2' (
SEt /p dirx=What is the directory of the music file:
echo start !dirx! >> %dir101%
goto menu
)
If '%choose%'=='-2' (
    echo Windows will open these sound files but may not automatically play them. If they are automatically played they should be opened one 

nessicary wait before wanted time.
goto menu
    )
If '%choose%'=='3' (
echo taskkill /PID wmplayer.exe >> %dir101%
goto menu
)
If '%choose%'=='-3' (
echo This closes the sound window when you play a sound. It should be played after a couple nessicary waits or when the sound is finished.
goto menu
)
If '%choose%'=='4' (
SEt /p thyme=How much milliseconds 250 is usual:
echo ping 192.168.1.1 -n 1 -w !thyme! ^>NUL >>%dir101%
goto menu
)
If '%choose%'=='-4' (
echo These waits are extremely important and should be used almost after every .txt.
goto menu
)
    If '%choose%'=='5' (
SEt /p point=what do you want the point to be labeled as:
echo :!point! >> %dir101%
goto menu
)
If '%choose%'=='-5' (
echo You use this to label points where your animation can go back to.
goto menu
)
If '%choose%'=='6' (
:Y
SEt /p answ=Is this a math variable y/n
If !answ!==y goto yes
If !answ!==n goto no
goto Y
:yes
SEt /p name=variable name
set /p form=variable formula
echo Set /a !name!=!form! >> %dir101%
goto T
:no
SEt /p name=variable name
set /p form=variable value
echo Set !name!=!form! >> %dir101%
:T
goto menu
)
If '%choose%'=='-6' (
echo Variables can be used to count the number of times something has shown so you. If you put %variable name% it will use the value of that 

variable.
goto menu
)
If '%choose%'=='7' (
SEt /p point=What point do you want to go to:
echo goto !point! >> %dir101%
goto menu
)
If '%choose%'=='-7' (
echo This is used to go back to points. THis is where you make infinite loops.
goto menu
)
If '%choose%'=='8' (
set /p var=which variable do you want to use
set /p string=What value should be questioned
SET /p poin=What is the name of the point
echo If '%!var!%'=='!string!' goto !poin! >> %dir101%
goto menu
)
If '%choose%'=='-8' (
echo IF sentences are usually used to do a command after a variable is a certain number.
goto menu
)
If '%choose%'=='-9' (
echo This is to close the batch.
goto menu
)
If '%choose%'=='9' (
echo Thanks for making
pause
exit /b
)

現在您可能看到需要是 %variablename% 的 %!var!% yeh 知道嗎? 我需要解釋更多,以便在修復此錯誤后完成其余批次的發貨! 在那之前,我仍然需要刪除它在開始時回答自己的問題的那部分!

這個問題涉及如何將批處理文件中的變量擴展為其他變量的名稱,然后解決這些問題。

您需要學習如何將代碼提煉成提出問題所需的最少代碼,然后提出特定問題。

話雖如此,我想我理解你的問題。

我相信您正在動態構建批處理腳本,並且您希望您的代碼看起來像

echo If '%someVar%'=='someString' goto someLabel

要使輸出中的百分比增加一倍,您需要做的就是將它們加倍

echo If '%%!var!%%'=='!string!' goto !poin! >> %dir101%

只是%% variable %%真的很簡單

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM