The topic is to reach a value, in a batch file with only one setted variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: The topic is to reach a value, in a batch file with only one setted variable

#16 Post by douglas.swehla » 05 Sep 2016 00:52

aGerman wrote:
douglas.swehla wrote:@aGerman,
I trust your translation more than Google's. Can you help us out here?


I can't translate bad English into good English as long as I don't understand a word. Sorry.

Steffen


I meant, can you translate my English to German? I hope it's passable :D

But also, there's this, from a few posts up. Looks like he wrote it in German then ran it through Google. Does it tell you anything useful about the task?
ledlightjungled wrote:Für den Code

Code: Select all

@echo off
setlocal enabledelayedexpansion

for /l %%g in (1,1,15) do (
   set /a i=i+1
   set day[!i!]=0%%g
)

for /l %%f in (16,1,30) do (
   set /a y=y+1
   set odd[!y!]=%%f
)

for /f "tokens=1,2 usebackq" %%d in ('[ ]') do set "mixit=altgraphik=%%d,closed=%%e"

set "%mixit:,=" & set "%"

for /l %%c in (1,1,15) do (
for /f "tokens=1,2 usebackq" %%a in ('!day[%%c]:~-2! !odd[%%c]!') do echo %altgraphik%%%a%closed% __ %altgraphik%%%b%closed%)

endlocal disabledelayedexpansion
pause


mit der Ausgabe

[01] __ [16]
[02] __ [17]
[03] __ [18]
[04] __ [19]
[05] __ [20]
[06] __ [21]
[07] __ [22]
[08] __ [23]
[09] __ [24]
[10] __ [25]
[11] __ [26]
[12] __ [27]
[13] __ [28]
[14] __ [29]
[15] __ [30]
Drücken Sie eine beliebige Taste . . .

habe ich für mich ein Format geschrieben, dass ich nicht ändere, um einzelne Teile der Ausgabe ändern zu können.

Mit einer ersten Batchdatei würde ich gerne auf den Parameter %1 einer zweiten Batchdatei zugreifen
können.

Der Parameter %1 sollte nur mit einer %variable% besetzt sein und ich würde gerne den Wert der Schale
%variable% nach belieben speichern und ändern können.

Die zweite Batchdatei sollte wenn möglich an der Stelle Parmeter %1 eine %variable% stehen haben,
mit der ich während einer command line Laufzeit, ohne den Befehl clear screen cls, die Nummer
01 der Ausgabe [01] ändern kann.

Das Ausgabe Format [01] bis [30] sollte sich nicht ändern, sondern nur die Nummern.

Für den Anfang sollte ich nur die Nummer 01, nach belieben ändern können.

ledlightjungled
Posts: 14
Joined: 11 Oct 2015 10:55

Re: The topic is to reach a value, in a batch file with only one setted variable

#17 Post by ledlightjungled » 05 Sep 2016 05:27

A short code saves work.
Any short version batch, for a text seen on screen is a progress i prefer to work with.
The code simplified is a progress.
I goldfish had less circles to swim, thank´s to douglas.swehla

To use the flex_columns for my work it takes a few days, but it worked.

The columns of numbers are a step to writte a batch menu.
Die Spalten mit den Nummern als Inhalt, sind ein Schritt ein batch Menü zu schreiben.

A batch File has one or more adresses. Parameter %1 %2 . . . shift %1 %2.
A number for example 52 can have many functions, through my case 40 + 12 or 30 + 22.
The written language i fit in a texfile are various functions or one or more variables.

Batch Files are a certain frame for used adresses from command line.
If parameter %1 would be inside a frame on screen and parameter %2 to shift %2 are a circle,
maybe there is a way to exit the parameters that hold functions or values.

I am not targeting just seen functions. A parameter adress can not be seen, it only can be done visible.
For example

Code: Select all

set string=%2


in this case the adress parameter %2 can be redirected with some saved values form command line commands.
A lot of information.

A list with five lines that is used with five or more files, to be scrolled up and down
is my priority to code batch files.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: The topic is to reach a value, in a batch file with only one setted variable

#18 Post by aGerman » 05 Sep 2016 12:02

douglas.swehla wrote:I meant, can you translate my English to German? I hope it's passable :D

I could but first of all we should understand his requiremens.

douglas.swehla wrote:But also, there's this, from a few posts up. Looks like he wrote it in German then ran it through Google. Does it tell you anything useful about the task?

I wasn't aware of any German posting :oops:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ledlightjungled wrote:Für den Code

Code: Select all

@echo off
... etc.

mit der Ausgabe

[01] __ [16]
...etc
Drücken Sie eine beliebige Taste . . .

habe ich für mich ein Format geschrieben, dass ich nicht ändere, um einzelne Teile der Ausgabe ändern zu können.

Translation:
For Code

Code: Select all

@echo off
... etc.

with the following output

[01] __ [16]
...etc
Press any key to continue . . .

I wrote a format that I don't change in order to be able to change the output partially.
(Sorry guys but that sentence doesn't make any sense to me and I don't understand it's meaning.)
(Tut mir leid Jungs, aber dieser Satz macht keinen Sinn für mich und ich verstehe ihn auch nicht.)


ledlightjungled wrote:Mit einer ersten Batchdatei würde ich gerne auf den Parameter %1 einer zweiten Batchdatei zugreifen können.

Translation:
With a first batch file I'd like to access Parameter %1 of a second batchfile.
(Okay you can't access a parameter but at least you could call a second batch file and pass a parameter.)
(Gut, du kannst nicht auf einen Parameter zugreifen, aber zumindest kannst du eine zweite Batchdatei aufrufen und dabei einen Parameter übergeben.)


ledlightjungled wrote:Der Parameter %1 sollte nur mit einer %variable% besetzt sein und ich würde gerne den Wert der Schale %variable% nach belieben speichern und ändern können.

Translation:
Parameter %1 should contain only one %variable% and I would like to save and change the "Schale" %variable% to any value I want.
(I don't have a clue how to translate "Schale" in that context. It's meaning is something like "nut shell" and doesn't make any sense, neither in German nor in English.)
(Ich habe keine Ahnung wie ich "Schale" in diesem Zusammenhang übersetzen soll. "Schale" macht hier weder in Deutsch, noch in Englisch irgendeinen Sinn.)


ledlightjungled wrote:Die zweite Batchdatei sollte wenn möglich an der Stelle Parmeter %1 eine %variable% stehen haben,
mit der ich während einer command line Laufzeit, ohne den Befehl clear screen cls, die Nummer
01 der Ausgabe [01] ändern kann.

Translation:
The second batch file should contain %variable% instead of parameter %1. This variable shall be used to Change the number 01 in the output [01] during the runtime of the batch file. CLS shall not be used.
(You can't pass a parameter to an already running process. Furtheremore you can't let the cursor jump back to a certain position without using a 3rd party program.)
(Du kannst keinen Parameter an einen bereits laufenden Prozess übergeben. Außerdem kannst du auch nicht den Cursor an eine bestimmte Stelle zurückspringen lassen, ohne ein fremdes Programm zu nutzen.)


ledlightjungled wrote:Das Ausgabe Format [01] bis [30] sollte sich nicht ändern, sondern nur die Nummern.

Translation:
The output format [01] to [30] shall not be changed. Only the values of the numbers.
(Understood.)
(Verstanden.)


ledlightjungled wrote:Für den Anfang sollte ich nur die Nummer 01, nach belieben ändern können.

Translation:
For the beginning only 01 shall be changed to any value that I want.
(Does it mean even if the first number was changed to say 05 the second value is still 02? At least it sounds like that.)
(Bedeutet das, dass auch wenn du die erste Zahl beispielsweise auf 05 änderst, die zweite immer noch 02 bleibt? Zumindest klingt das so.)

Steffen

ledlightjungled
Posts: 14
Joined: 11 Oct 2015 10:55

Re: The topic is to reach a value, in a batch file with only one setted variable

#19 Post by ledlightjungled » 05 Sep 2016 14:10

Die Ausgabe durch den Bildschirm, nur die ersten fünf Wörter lassen sich direkt übersetzen.
The issue through the screen, only the first five words are translated directly.

I started to wrote in english sentences that fit my issue.
I am not exhausted from the confrontation, i just hope the pain to read is not an ake.

Your reply is welcome.
I start to comment the end of your reply.

Yes, the second value can still be 02.
I just try to show my comment with a possible code to follow.

Code: Select all

set virus=%1
echo %virus%


A.bat rem This can be the name of the first batch file.

Code: Select all

for /f "tokens=1 eol=C" %%a in ('call A.bat windows') do echo %%a
pause


Batch.bat rem A possible name of the second batch file.

An output from a for /L command token %%b, is when possible to replace the word windows in the for /F command above.
If the step in the for /L command would be just 1 there is maybe a chance to change the ouput.

You wrote a third programm should be used, i concider that within reach my possibilities.

A setted variable like
%variable%
is a shell.

I have not finished to search the redirection of an parameter, respektive batch file adress, to a shell.

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: The topic is to reach a value, in a batch file with only one setted variable

#20 Post by douglas.swehla » 05 Sep 2016 17:13

ledlightjungled wrote:I started to wrote in english sentences that fit my issue.
I am not exhausted from the confrontation, i just hope the pain to read is not an ake.

It's not an ache, but it is difficult. What is your native language? There are many international users here. Maybe one of them can help you ask your questions.

ledlightjungled wrote:

Code: Select all

set virus=%1
echo %virus%


A.bat rem This can be the name of the first batch file.

Code: Select all

for /f "tokens=1 eol=C" %%a in ('call A.bat windows') do echo %%a
pause


Batch.bat rem A possible name of the second batch file.


A few things about the FOR command:
  • It automatically uses only the first token, unless you tell it different, so "tokens=1" is not needed.
  • EOL means "End Of Line". This is where the command stops looking for more tokens. EOL characters will usually be punctuation or special characters like TAB, comma (,), semicolon (;), period (.), and so on. You can use "C" if you want to, but it is strange, and it is not needed here.
  • The CALL command does not work in the ...IN ('command') section. Just use the batch file directly. (You can use CALL in the ... DO (command) section.)

Code: Select all

:: Batch.bat
for /f %%a in ('A.bat windows') do echo %%a


The code above will output "windows". So far, so good.

ledlightjungled wrote:An output from a for /L command token %%b, is when possible to replace the word windows in the for /F command above.
If the step in the for /L command would be just 1 there is maybe a chance to change the ouput.

I think you want to create an indexed list of values (an array) and then access elements in the list using the variables in a FOR /L loop. Here are some ways to do that:

Code: Select all

:: use_index.bat
@echo off
setlocal enableDelayedExpansion

set "1=alpha"
set "2=bravo"
set "3=charlie"
set "4=delta"
set "5=echo"
set "6=foxtrot"
set "7=golf"
set "8=hotel"
set "9=india"
set "10=juliet"
set "11=kilo"
set "12=lima"
set "13=mike"
set "14=november"
set "15=oscar"
set "16=papa"
set "17=quebec"
set "18=romeo"
set "19=sierra"
set "20=tango"
set "21=uniform"
set "22=victor"
set "23=whiskey"
set "24=x-ray"
set "25=yankee"
set "26=zulu"

for %%A in (2 7 15) do echo [%%A] __ [!%%A!]
pause

for /l %%L in (1,1,5) do echo [%%L] __ [!%%L!]
pause   

for /l %%L in (1,1,13) do (
   call :set_col2 %%L 13 num2 val2
   echo [%%L,!%%L!] __ [!num2!,!val2!]
)

endlocal
exit /b

:set_col2
   setlocal
   rem :: Called subroutines can accept parameters just like batch files can.
   set /a num=%~1+%~2
   set val=!%num%!
   (endlocal & set "%~3=%num%" & set "%~4=%val%")
goto :eof


ledlightjungled wrote:A setted variable like
%variable%
is a shell.


It is better to say "variable" than "shell". In the context of scripting, we usually use "shell" to mean the program that interacts with the operating system. On Windows, that is CMD.EXE. On *nix systems, common shells include sh and bash.

In the example 'set virus=windows', we can say that 'virus' is the variable name, and that 'windows' is the variable value. If you just say variable, we can guess variable name or variable value based on context. In CMD.EXE, variables always have a value -- you cannot declare a variable and then assign a value to it later. So, there is no such thing as an empty variable.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: The topic is to reach a value, in a batch file with only one setted variable

#21 Post by Aacini » 05 Sep 2016 18:51

douglas.swehla wrote:I think you want to create an indexed list of values (an array) and then access elements in the list using the variables in a FOR /L loop. Here are some ways to do that:

Code: Select all

:: use_index.bat
@echo off
setlocal enableDelayedExpansion

set "1=alpha"
set "2=bravo"
set "3=charlie"
set "4=delta"
. . .



It is a bad idea to use variables with numbers as names. Although you may simulate an array in a Batch file using several different notations, you may also just use the standard array notation with an array name and an index enclosed in square brackets this way: name[index], that is clearer. For example:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set index=0
for %%a in (alpha bravo charlie delta echo foxtrot golf hotel india juliet kilo lima mike
            november oscar papa quebec romeo sierra tango uniform victor whiskey x-ray yankee zulu) do (
   set /A index+=1
   set "vector[!index!]=%%a"
)

for %%A in (2 7 15) do echo [%%A] __ [!vector[%%A]!]
pause

for /l %%L in (1,1,5) do echo [%%L] __ [!vector[%%L]!]
pause   

Antonio

ledlightjungled
Posts: 14
Joined: 11 Oct 2015 10:55

Re: The topic is to reach a value, in a batch file with only one setted variable

#22 Post by ledlightjungled » 06 Sep 2016 05:45

I have grown up with two languages.
The slovenien and german language.
My syntax is not settled for the spoken part of english language.
There are very rare possibilities to speak with others english.

I look forward to search for answers on other sites, too.
The Microsoft TechNet Site is an option, but the contract is long as an river.

What i have done is to delete the tokens code expression and the call.
I cannot pass the "eol=C" parameter "option".

The output with my cmd environment has additional two lines.

>echo C:\Users\etc.
>echo C:\Users\etc.

To skip that option i have to use the parameter "eol=C" "option".

The common use to say "variable" and not "shell" is possible to change.
Thank you for your examples, they are usefull for my creative sens.

My question is still not answered, is it possible to use a parameter like an attachment for a "bulb" or on off function.
(The cursore is a core, i search for).

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: The topic is to reach a value, in a batch file with only one setted variable

#23 Post by foxidrive » 07 Sep 2016 18:01

ledlightjungled wrote:I have grown up with two languages.
The slovenien and german language.
My syntax is not settled for the spoken part of english language.
There are very rare possibilities to speak with others english.


Your English expression is very bad.
I cannot understand 90% of what you write.

I am being clear here so that you understand and not to judge your skill with English.

ledlightjungled
Posts: 14
Joined: 11 Oct 2015 10:55

Re: The topic is to reach a value, in a batch file with only one setted variable

#24 Post by ledlightjungled » 08 Sep 2016 07:59

I have to improve my contributions.

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: The topic is to reach a value, in a batch file with only one setted variable

#25 Post by douglas.swehla » 08 Sep 2016 12:07

ledlightjungled wrote:I have to improve my contributions.


When you write, try to use short, simple sentences. Use literal terms, and avoid figures of speech like "long as a river". Those are okay in conversation, but in technical writing, it is better to be clear than to be creative. Many fluent English speakers here have difficulty describing their problems, because the ideas are complicated. There is no need to make the writing complicated also.

I suggest that you write your responses in Slovenian, and then use Google to translate them into German. If the German translation is not clear to you, then you need to simplify the Slovenian. Repeat those steps until the German translation makes sense to you, then translate the Slovenian to English. Post all three versions, and hopefully we'll be able to understand at least one of them.

douglas.swehla
Posts: 75
Joined: 01 Jun 2016 09:25

Re: The topic is to reach a value, in a batch file with only one setted variable

#26 Post by douglas.swehla » 08 Sep 2016 13:12

ledlightjungled wrote:What i have done is to delete the tokens code expression and the call.
I cannot pass the "eol=C" parameter "option".

The output with my cmd environment has additional two lines.

>echo C:\Users\etc.
>echo C:\Users\etc.

To skip that option i have to use the parameter "eol=C" "option".


In a case like that, we usually use FIND or FINDSTR to filter out whole lines. If you use an EOL character to filter, you may accidentally exclude something you want to keep. Try this instead:

Code: Select all

for /f %%a in ('A.bat windows ^| find /v "C:\Users\"') do echo %%a



ledlightjungled wrote:Is it possible to use a parameter like an attachment for a "bulb" or on off function.
(The cursore is a core, i search for).

Within a batch, you can test to see if some variable is defined, or if it matches some value. If the test succeeds, do one thing, if it fails, do something else, or do nothing. I think you mean "switch" when you say "bulb". I don't understand what you mean by "cursor is a core".

These are all calls to subroutines instead of separate batch files, but the same logic applies.
Not tested:

Code: Select all

:: switches.bat
@echo off

echo :: Passing any argument to :on_off turns the switch to OFF, even if the argument is "ON".
call :on_off
call :on_off -off
call :on_off whatever
call :on_off -on
echo\

echo :: The switch only turns on if the argument is TRUE (not case sensitive).
call :true_false
call :true_false true
call :true_false TruE
call :true_false false
call :true_false whatever
echo\

echo :: The switch only works if you pass a number between 1 and 3.
call :menu
call :menu 0
call :menu 1
call :menu 2
call :menu 3
call :menu 4
call :menu X
echo\

exit /b
::----------------------------------------------------------------------------

:on_off [off_switch]
    if "%~1" neq "" (@echo Switch is OFF.) else (@echo Switch is ON.)
goto :eof

:true_false [true]
    if /i "%~1" equ "true" (@echo Switch is ON.) else (@echo Switch is OFF.)
goto :eof

:menu option
    setlocal
    set /a option=%~1
    if option gtr 0 if option leq 3 goto :menu_option_%option%
    @echo You did not choose a valid option.
    endlocal
goto :eof

:menu_option_1
    @echo You chose option %option%.
    endlocal
goto :eof

:menu_option_2
    @echo You chose option %option%.
    endlocal
goto :eof

:menu_option_3
    @echo You chose option %option%.
    endlocal
goto :eof



Please post the whole script (or set of scripts) that you are working on. Give a file name for each script. Explain what the project is supposed to do. Give examples of the output that you are getting now, and what you want to get when the script works properly. Seeing the whole problem lets us know if we're working on the right thing.

ledlightjungled
Posts: 14
Joined: 11 Oct 2015 10:55

Re: The topic is to reach a value, in a batch file with only one setted variable

#27 Post by ledlightjungled » 14 Sep 2016 06:01

Within the options in reach i try to redirect the cmd commands to build a menu.

https://1drv.ms/i/s!AuqiErX9tbF2chfkRmP4tCuqJ-w

Next to the squared numbers on the right five file names have been echoed.
The task to aim is fifteen files to scroll with up and down.

The numbers on the left have to scroll within changeable positions from one to five.
Also up and down.

Under the squares on the left bottom side one square is left for a confirmation with a number one or two,three,four,five.

For my work i have set two required steps.

Number one

the modified code

Code: Select all

@echo off
setlocal enabledelayedexpansion

for /l %%L in (1,1,15) do (
   set day=0%%L
   set /a odd=%%L+15
   echo [!day:~-2!] __ [!odd!]
)
pause > nul
endlocal
exit /b


modfied by douglas.swehla

Number two

codes for changeable steps in reach

[code@echo off
setlocal enabledelayedexpansion

for /f "Tokens=1 usebackq" %%i in ("longU.txt") do (
set var=%%i
if defined var set data=!data! !var!)

for /f "tokens=1-26 usebackq" %%a in ('!data!') do (
echo %%a %%b %%c %%d %%e
echo %%f %%g %%h %%i %%j
echo %%k %%l %%m %%n %%o
echo %%p %%q %%r %%s %%t %%u
echo %%v %%w %%x %%y
echo %%z)

endlocal disabledelayedexpansion
pause >nul
][/code]

longU.txt
https://1drv.ms/i/s!AuqiErX9tbF2c0jONlt2Jn95P4c

I wrote my text without google translations.
Just for a last step with my textfile.
Next time if a reply is to be answered i aim to use your suggestions.
with my common regards

Post Reply