Page 1 of 1
set var= if true (goto) else (echo.&echo.%var%)
Posted: 26 Sep 2012 12:54
by Jess Selien
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%)
Re: set var= if true (goto) else (echo.&echo.%var%)
Posted: 26 Sep 2012 14:36
by Jess Selien
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...
Re: set var= if true (goto) else (echo.&echo.%var%)
Posted: 26 Sep 2012 19:01
by Squashman
This code makes absolutely no sense.
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%)
Posted: 26 Sep 2012 21:38
by Liviu
Jess Selien wrote:Another example
[...]
if statement equ true (%streamlog%) else echo.%streammsg%
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.
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%
...but that might also (and likely) be the wrong answer to a question you never fully articulated.
Liviu
Re: set var= if true (goto) else (echo.&echo.%var%)
Posted: 26 Sep 2012 23:12
by foxidrive
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)
)
Re: set var= if true (goto) else (echo.&echo.%var%)
Posted: 28 Aug 2013 16:32
by Jess Selien
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!