Script changed by input
Moderator: DosItHelp
Script changed by input
hi,
I need to changed my script like this:
i have a function that doing things and i want it to react like this:
I'm setting in the beginning the variable.\
If it set to null
Set id=null
It's good like it's working now.
If it set to number :
Set id=0,1
The script will run my function for two time each time with other parameters (first time with 0 and second with 1 )
The script could be take input like 0,1,2,3(4 times it will execute )
Thanks in advance....
I need to changed my script like this:
i have a function that doing things and i want it to react like this:
I'm setting in the beginning the variable.\
If it set to null
Set id=null
It's good like it's working now.
If it set to number :
Set id=0,1
The script will run my function for two time each time with other parameters (first time with 0 and second with 1 )
The script could be take input like 0,1,2,3(4 times it will execute )
Thanks in advance....
Re: Script changed by input
The name of the function were good to know, as it should be called. I assume its name is myFunc.mor.bas wrote:hi,
(...) i have a function that doing things (...) The script will run my function (...)
I assume the setting of the variable works completely although the "it's working now" is within the full description.mor.bas wrote:(...) If it set to null (...) I'm setting in the beginning the variable (....) It's good like it's working now. (...) If it set to number : (...)
I assume this is, what you want to do.mor.bas wrote:The script will run my function for two time each time with other parameters(first time with 0 and second with 1 )
The script could be take input like 0,1,2,3(4 times it will execute )
If it is so, this may work:
Code: Select all
for %%a in (%id:;= %) do call :myFunc %%a
penpen
Re: Script changed by input
Hi,
I didnt understand what (%id:;= %) mean?
I didnt understand what (%id:;= %) mean?
Re: Script changed by input
Penpen, you don't need to change the delimiter to a space to have the for loop work correctly. It will parse the ID variable just fine with a semicolon or a comma as the delimiter.
Re: Script changed by input
Hi,
It's not working for me
Let's me explain more...
In the first of the script i set it like
SET ID=0,1,2
Then my func should run three time
first time setting a varible that it's used inside to 0
second time setting a varible that it's used inside to 1
third time setting a varible that it's used inside to 2
Thanks in advance...
It's not working for me
Let's me explain more...
In the first of the script i set it like
SET ID=0,1,2
Then my func should run three time
first time setting a varible that it's used inside to 0
second time setting a varible that it's used inside to 1
third time setting a varible that it's used inside to 2
Thanks in advance...
Re: Script changed by input
Code: Select all
@echo off
for /L %%a in (1,1,3) do (
echo %%a
)
pause
Re: Script changed by input
Hi,
Two things :
1.I want it to be dynamical according to what i'm writing in the id varible.
It can be :
SET ID=0,1 (to run twice) or SET ID=0 (to run once).
2. In the loop inside I want to set my varible to the id input
It is right to write:
SET FACILITY=%%a ?
Thanks....
Two things :
1.I want it to be dynamical according to what i'm writing in the id varible.
It can be :
SET ID=0,1 (to run twice) or SET ID=0 (to run once).
2. In the loop inside I want to set my varible to the id input
It is right to write:
SET FACILITY=%%a ?
Thanks....
Re: Script changed by input
CoolSquashman wrote:Penpen, you don't need to change the delimiter to a space to have the for loop work correctly. It will parse the ID variable just fine with a semicolon or a comma as the delimiter.
mor.bas wrote:Hi,
It's not working for me
Let's me explain more
...
This example works, but i assumed you have coded all other, a full example is:
Code: Select all
@echo off
setlocal
SET ID=0,1,2
if not "%ID%" == "null" for %%a in (%ID%) do call :myFunc %%a
endlocal
goto :eof
:myFunc
SET FACILITY=%1
echo FACILITY=%FACILITY%
goto :eof
penpen
Edit: added if not "%ID%" == null
Edit2: added edit notes
Edit3 corrected set facility line
Last edited by penpen on 22 Jul 2013 06:38, edited 3 times in total.
-
- Posts: 184
- Joined: 21 Feb 2013 15:54
Re: Script changed by input
The way to do this would be to ask for the input of sequence of numbers. Put that in a variable.
Then have a for loop (not for /f loop) iterate over each character of that variable because it uses commas as delims.
The last assigned placeholder of the loop would be the highest number of the variable you want to use in yoru function. Then just iterate from 0 up to the highest number, changing the variable by adding one every time, and using the variable within your function until the value is greater than the highest number.
Then have a for loop (not for /f loop) iterate over each character of that variable because it uses commas as delims.
The last assigned placeholder of the loop would be the highest number of the variable you want to use in yoru function. Then just iterate from 0 up to the highest number, changing the variable by adding one every time, and using the variable within your function until the value is greater than the highest number.
Re: Script changed by input
Ah, i didn't understand to get the input from user, so here is a example doing that, too:
Code: Select all
@echo off
setlocal enableDelayedExpansion
set "input="
set /p "input=Please type in a non negative int32 number: "
if defined input (
set /a "parsedInput=input"
if not "!input!" == "!parsedInput!" set "parsedInput=null"
if !parsedInput! LSS 0 set "parsedInput=null"
) else (
set "parsedInput=null"
)
if "%parsedInput%" == "null" (
set "ID=null"
) else (
set "ID="
for /l %%a in (0,1,%parsedInput%) do set "ID=!ID!,%%a"
set "ID=!ID:~1!
)
if not "%ID%" == "null" for %%a in (%ID%) do call :myFunc %%a
endlocal
goto :eof
:myFunc
SET FACILITY=%1
echo FACILITY=%FACILITY%
goto :eof