Is there any way to set this line of code to a variable which I can execute multiple times in a program?
set date=
set var= if true (goto) else (echo.&echo.%date%)
...
set date=Monday&%var%
set date=Tuesday&%var%
...etc...
In this example, what results is the date variable is set to blank and is that way through out the code. Is there any way to use some type of escape char for this to work?
Workaround=
set date=Monday
if true (goto) else (echo.&echo.%date%)
set date=Tuesday
if true (goto) else (echo.&echo.%date%)
set var= if true (goto) else (echo.&echo.%var%)
Moderator: DosItHelp
-
- Posts: 13
- Joined: 26 Sep 2012 12:08
Re: set var= if true (goto) else (echo.&echo.%var%)
My goal is finding a way to shorten code. Not necessarilly prove the date is correct.
Another example -
set streampath=D:\temp\Output.log
set streammsg=
set streamlog=echo.%streammsg%>>%streampath%
set streammsg=Hello world
if statement equ true (%streamlog%) else echo.%streammsg%
set streammsg=Today is Tuesday
if statement equ true (%streamlog%) else echo.%streammsg%
set streammsg=It is cool out today
if statement equ true (%streamlog%) else echo.%streammsg%
etc...
Instead of typing:
set streammsg=Hello world
if statement equ true (echo.%streammsg%>>%streampath%) else echo.%streammsg%
etc...
Another example -
set streampath=D:\temp\Output.log
set streammsg=
set streamlog=echo.%streammsg%>>%streampath%
set streammsg=Hello world
if statement equ true (%streamlog%) else echo.%streammsg%
set streammsg=Today is Tuesday
if statement equ true (%streamlog%) else echo.%streammsg%
set streammsg=It is cool out today
if statement equ true (%streamlog%) else echo.%streammsg%
etc...
Instead of typing:
set streammsg=Hello world
if statement equ true (echo.%streammsg%>>%streampath%) else echo.%streammsg%
etc...
Re: set var= if true (goto) else (echo.&echo.%var%)
This code makes absolutely no sense.
How is anyone suppose to logically determine if "Hello World" is a true statement. Same goes for "It is cool out today".
State something more specific as to what you want accomplished.
Code: Select all
set streammsg=Hello world
if statement equ true (%streamlog%) else echo.%streammsg%
set streammsg=It is cool out today
if statement equ true (%streamlog%) else echo.%streammsg%
How is anyone suppose to logically determine if "Hello World" is a true statement. Same goes for "It is cool out today".
State something more specific as to what you want accomplished.
Re: set var= if true (goto) else (echo.&echo.%var%)
What language is that supposed to be in? In a batch file, the "else" part would get executed every time. Please take your own advice from the other thread and post an intelligible, answerable question.Jess Selien wrote:Another example
[...]
if statement equ true (%streamlog%) else echo.%streammsg%
It might be that what you're after is...
Code: Select all
@echo off & setlocal
set streamlog=echo.%%streammsg%%^>^>"=%temp%\Output.log"
set statement=true
call :duh
set statement=false
call :duh
endlocal & goto :eof
:duh
set streammsg=Hello world
if %statement% equ true (call %streamlog%) else echo.%streammsg%
Liviu
Re: set var= if true (goto) else (echo.&echo.%var%)
Your problem might be handled in a loop where you execute something with a range of items.
The better your description of the problem is, the better the answer you will get.
@echo off
for %%a in (monday tuesday wednesday thursday friday) do (
call :routine %%a
if defined result (do this) else (do that)
)
The better your description of the problem is, the better the answer you will get.
@echo off
for %%a in (monday tuesday wednesday thursday friday) do (
call :routine %%a
if defined result (do this) else (do that)
)
-
- Posts: 13
- Joined: 26 Sep 2012 12:08
Re: set var= if true (goto) else (echo.&echo.%var%)
Sorry for the late reply and poor description.
Liviu provided the answer I was looking for.
I want the dos batch code the same to be executed multiple times but yet have a different value for the variable.
set new value
call :duh
set new value
call :duh
It is exactly what I was looking for. Thanks!
Liviu provided the answer I was looking for.
I want the dos batch code the same to be executed multiple times but yet have a different value for the variable.
set new value
call :duh
set new value
call :duh
It is exactly what I was looking for. Thanks!