Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Change variable for each loop  (Read 3192 times)

0 Members and 1 Guest are viewing this topic.

zask

    Topic Starter


    Intermediate

    • Experience: Experienced
    • OS: Other
    Change variable for each loop
    « on: April 12, 2016, 06:48:54 PM »
    Okay im trying to basically display text from a text file inside the batch file using a trick i found on the internet.
    I've notice a few problems though, one is that i need a variable that can change for each loop that the variable is in. here is my code.

    @ECHO OFF

    REM Make text file
    Echo %~DP0%~N0%~X0 >> %TEMP%\Somefile.Zask

    REM search for all lines in that file and append them to variables in this file

    Setlocal EnableExtensions EnableDelayedExpansion
    for /f "delims=" %%A in (%TEMP%\Somefile.zask) do (
    Set /a C+=1
    Set X[!C!]=%%A
    )
    Set X
    echo !C!
    pause
    set /a Y=1

    REM go into a loop once for each line in the text file and then echo each line

    :loop
    if %Y% lss !C! (

    REM here is the problem, i need to make a variable that will change each time the user goes through a loop.
    REM for example "%x[%Y%]%" would display this each loop ; %x[1]%, %x[2]%, %x[3]%, %x[4]% ~so on, REM but i just don't know how to do it.

      echo %x[%Y%]%


      pause>nul
      set /a Y+=1
      goto :loop
    )

    echo end of loop
    pause

    Salmon Trout

    • Guest
    Re: Change variable for each loop
    « Reply #1 on: April 13, 2016, 02:14:45 PM »
    Google for, or search alt.msdos.batch.nt on (Google Groups) for "call set".

    zask

      Topic Starter


      Intermediate

      • Experience: Experienced
      • OS: Other
      Re: Change variable for each loop
      « Reply #2 on: April 14, 2016, 08:43:46 PM »
      Google for, or search alt.msdos.batch.nt on (Google Groups) for "call set".

      Okay thank for the help, but i found a solution,  was trying to do something like this.

      @ECHO Off
      echo encrypt batch file
      echo.
      set /P "FILE= Enter the name of the batch file that you wish to encrypt (Example; "Somefile") : "
      set /A CREATEKEY=%random% %%200 +2

      Setlocal EnableExtensions EnableDelayedExpansion
      for /f "delims=" %%A in (%FILE%.txt) do (
      Set /a C+=1
      Set X[!C!]=%%A
      set CHECKPASSWORD=%%A
      set CHECKKEY=%%B
      set CHAR=0123456789bhfcjrwmudaxopvntzlqeisykg

      for /l %%C in (10 1 36) do (
      for /f %%D in ("!CHAR:~%%C,1!") do (
      set /a MATH=%%C*%CREATEKEY%
      for /f %%E in ("!MATH!") do (

      set "CHECKPASSWORD=!CHECKPASSWORD:%%D=-%%E!"
      )
      )
      )

      echo !CHECKPASSWORD! >> %FILE%.Zask
      )
      Set X

      Setlocal DisableExtensions DisableDelayedExpansion

      echo @ECHO Off >> Decrypt.bat
      echo. >> Decrypt.bat
      echo Setlocal EnableExtensions EnableDelayedExpansion >> Decrypt.bat
      echo for /f "delims=" %%%%A in (%FILE%.zask) do ( >> Decrypt.bat
      echo Set /a C+=1 >> Decrypt.bat
      echo Set X[!C!]=%%%%A >> Decrypt.bat
      echo set CHECKPASSWORD=%%%%A >> Decrypt.bat
      echo set CHECKKEY=%%%%B >> Decrypt.bat
      echo set CHAR=0123456789bhfcjrwmudaxopvntzlqeisykg >> Decrypt.bat
      echo. >> Decrypt.bat
      echo for /l %%%%C in (10 1 36) do ( >> Decrypt.bat
      echo for /f %%%%D in ("!CHAR:~%%%%C,1!") do ( >> Decrypt.bat
      echo set /a MATH=%%%%C*%CREATEKEY% >> Decrypt.bat
      echo for /f %%%%E in ("!MATH!") do ( >> Decrypt.bat
      echo. >> Decrypt.bat
      echo set "CHECKPASSWORD=!CHECKPASSWORD:%%%%E=%%%%D!" >> Decrypt.bat
      echo ) >> Decrypt.bat
      echo ) >> Decrypt.bat
      echo ) >> Decrypt.bat
      echo for /f %%%%F in ("!CHECKPASSWORD!") do ( >> Decrypt.bat
      echo set "CHECKPASSWORD=!CHECKPASSWORD:-=!" >> Decrypt.bat
      echo !CHECKPASSWORD! >> Decrypt.bat
      echo ) >> Decrypt.bat
      echo ) >> Decrypt.bat
      echo Set X >> Decrypt.bat

      Kinda lame just bored though.