So I try Writing the codes to generate random characters and I want to make the screen always at the same size but when I tried using mode command it clears all text or you can call it entire screen
Here is the code:
:startprg
mode con: cols=120 lines=24
setlocal EnableDelayedExpansion
set char=abcdeijklmnstuvwxyzABCDETUVYZ23456789^^%%_`^^%%_`^^%%_`^^%%_`^^%%_`☺☻♥♦♣♠◘•○☺☻♥♦♣♠◘♂♀q7•-6○Z♂n¡* /*-+##$*()_=-=+
set count=0
set hla=0
:Number
set hla=120
set /a length=-1 + !hla!
:Loop
set /a count+=1
set /a rand=%Random%%%61
set buffer=!buffer!!char:~%rand%,1!
if !count! leq !length! goto Loop
title ^!buffer!
echo ^!buffer!
set /a length+=1
endlocal
goto startprg
Please help me I'm on Windows 10 and I don't know how to fix this problem
Currently each time you goto :startprg you reset the mode. Simply move the label to after mode con: in order to initiate it only once. So it should be:
#echo off
mode con: cols=120 lines=24
:startprg
setlocal EnableDelayedExpansion
So the full code would be as:
#echo off
mode con: cols=120 lines=24
:startprg
setlocal EnableDelayedExpansion
set char=abcdeijklmnstuvwxyzABCDETUVYZ23456789^^%%_`^^%%_`^^%%_`^^%%_`^^%%_`☺☻♥♦♣♠◘•○☺☻♥♦♣♠◘♂♀q7•-6○Z♂n¡* /*-+##$*()_=-=+
set count=0
set hla=0
:Number
set hla=120
set /a length=-1 + !hla!
:Loop
set /a count+=1
set /a rand=%Random%%%61
set buffer=!buffer!!char:~%rand%,1!
if !count! leq !length! goto Loop
title ^!buffer!
echo ^!buffer!
set /a length+=1
endlocal
goto startprg
Related
I have these 2 scripts .bat working fine individually, but I want to combine them into one, so they can run their commands at the same time, instead of consecutively.
Let me explain my idea:
I'm testing a program made by a German, which consists of showing bmp images on your cmd console (also using gifs frames on a loop to show animated images as well). the plugin made for this to work is called Insertbmp.exe:
#echo off
title BMP console
cd bin\sprimg
pause
cls
color 0f
mode 81,41
cls
set name=openedk
:loop1
openedk\insertbmp /p:"%name%%loop%.bmp" /x:0 /y:0 /z:0
set /a loop=%loop%+1
if not exist openedk\%name%%loop%.bmp goto endofloop1
timeoutms 100
goto loop1
:endofloop1
set /a lo=%lo%+1
set loop=0
if %lo% lss 4 goto loop1
set lo=0
pause
color f0
mode 62,32
cls
set name=alien
:loop2
alien\insertbmp /p:"%name%%loop%.bmp" /x:0 /y:0 /z:0
set /a loop=%loop%+1
if not exist alien\%name%%loop%.bmp goto endofloop2
timeoutms 100
goto loop2
:endofloop2
set /a lo=%lo%+1
set loop=0
if %lo% lss 4 goto loop2
set lo=0
pause
color 0f
mode 62,22
cls
set name=sleep
:loop3
sleep\insertbmp /p:"%name%%loop%.bmp" /x:0 /y:18 /z:0
set /a loop=%loop%+1
if not exist sleep\%name%%loop%.bmp goto endofloop3
timeoutms 100
goto loop3
:endofloop3
set /a lo=%lo%+1
set loop=0
if %lo% lss 3 goto loop3
set lo=0
pause
color 0f
mode 33,2
cls
echo End of TEST file
pause
exit
the other one is also a batch script made to type lines by itself, it's called ghost typer:
#echo off
:: Ghost typer
setlocal enableextensions enabledelayedexpansion
set lines=7
set "line1=This was a triumph"
set "line2=I'm making a note here: huge success"
set "line3=It's hard to overstate my satisfaction"
set "line4=Aperture science"
set "line5=We do what we must because we can"
set "line6=For the good of all of us"
set "line7=Except the ones who are dead"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
for /L %%a in (1,1,%lines%) do set num=0&set "line=!line%%a!"&call :type
pause>nul
goto :EOF
:type
set "letter=!line:~%num%,1!"
set "delay=%random%%random%%random%%random%%random%%random%%random%"
set "delay=%delay:~-6%"
if not "%letter%"=="" set /p "=a%bs%%letter%" <nul
:: adjust the 3 in the line below: higher is faster typing speed
for /L %%b in (1,2,%delay%) do rem
if "%letter%"=="" echo.&goto :EOF
set /a num+=1
goto :type
Basically, what I have in mind is: run those commands simultaneously on the same line so it doesn't consecutively run them, giving me a cmd console typing whatever I want by it self, while showing me my animated images one by one which I already have on my folder.
on my current situation, it only runs the loop command before it runs the typer codes.
any suggestions?
(I'm rookie on coding anything, sorry)
I'm making a card game, so I'm trying to set a specific amount of times a number can be used, so I'm basically looking for either a way to do "double variables" or a way around them:
#echo off
color 0a
set 1=13
set 2=13
set 3=13
set 4=13
:loop
if %counter%==0
goto :skip
set /a card=%random%*4/32767+1
set %card%=%%card%%-1
goto :loop
:skip
....
I think this is the logic you are going for. Your assumption was correct. You do need double variable expansion. This can be achieved two ways. With Delayed Expansion or using the CALL command. I chose the latter. For the example I set the counter to 13 and kept echoing the contents of each of the variables after each loop.
#echo off
set _1=13
set _2=13
set _3=13
set _4=13
set "counter=13"
:loop
IF "%counter%"=="0" goto skip
set /a card=%random% %% 4 +1
call set /a _%card%=%%_%card%%% - 1
echo _1=%_1%
echo _2=%_2%
echo _3=%_3%
echo _4=%_4%
set /a counter-=1
goto :loop
:skip
pause
EDIT: Now that I look at that again, you actually don't need to use the CALL at all or delayed expansion because the SET command will take care of it for you.
#echo off
set _1=13
set _2=13
set _3=13
set _4=13
set "counter=13"
:loop
IF "%counter%"=="0" goto skip
set /a card=%random% %% 4 +1
set /a _%card%-=1
echo _1=%_1%
echo _2=%_2%
echo _3=%_3%
echo _4=%_4%
set /a counter-=1
goto :loop
:skip
I am creating a password generator in batch, and had to use some help from the internet to finish it, but I am having difficulty interpreting the section of the code I had to borrow. Would someone please explain it?
:generate
#Echo Off
color 0a
set /P usernumberlength="What length do you want your password to be? "
pause
cls
Setlocal EnableDelayedExpansion
Set RNDLength=%usernumberlength%
/// from here
Set Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Set Str=%Alphanumeric%987654321
:loop
IF NOT "%Str:~18%"=="" SET Str=%Str:~9%& SET /A Length+=9& GOTO :loop
SET tmp=%Str:~9,1%
SET /A Length=Length+tmp
Set count=0
SET RndAlphaNum=
:loop2
Set /a count+=1
SET RND=%Random%
Set /A RND=RND%%%Length%
SET RndAlphaNum=!RndAlphaNum!!Alphanumeric:~%RND%,1!
If !count! lss %RNDLength% goto loop2
/// to here
Echo Password is: is !RndAlphaNum!
Echo Now choose what you want to do.
Echo 1) Go back to the beginning
Echo 2) Exit
set input=
set /p input= Choice:
if %input%==1 goto generate
if %input&==2 exit
pause
This working example (from the code you provided) contains the all-you-need section.
#echo Off
color 0a
setlocal enabledelayedexpansion
:generate
set /p usernumberlength="What length do you want your password to be? "
rem ----- begin section all you need -----
Set Alphanumeric=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
rem "Length" is the string length of %alphanumeric%
Set Length=62
set count=0
rem "RndAlphaNum" is the output
SET RndAlphaNum=
:loop
Set /a count+=1
Set /A RND=%Random% %% %Length%
SET RndAlphaNum=!RndAlphaNum!!Alphanumeric:~%RND%,1!
if !count! lss %usernumberlength% goto loop
rem ----- end section all you need -----
echo Password is: !RndAlphaNum!
goto generate
I've researched about operand and operators, set /a , and setlocal EnableDelayedExpansion from this website but still somehow my code ends up telling
me that my operand is missing.
#echo off
cls
setlocal EnableDelayedExpansion
color 0a
title Fibonacci Lister
:Fibonacci
cls
set /a n1=1
echo %n1%
set /a n2=1
echo %n2%
set /a j=3
:loopfunction
set /a n%j%=!n%j-1%!+!n%j-2%!
echo !n%j%!
set /a j=%j%+1
goto :loopfunction
So I wanted to know what is the problem here. It is probably in line 14 where
the code is complex and hard to understand easily.
On line #14, you were using a variables named %j-1% and %j-2% which weren't declared.
Updated Script:
#echo off
setlocal EnableDelayedExpansion
color 0a
title Fibonacci Lister
:Fibonacci
set /a n1=1
echo %n1%
set /a n2=1
echo %n2%
set /a j=3
:loopfunction
set /a j1=j-1&set /a j2=j-2
set /a n%j%=!n%j1%!+!n%j2%!
if "!n%j%!"=="1836311903" goto :EOF
echo !n%j%!
set /a j=j+1
goto :loopfunction
#echo off
setlocal enableextensions disabledelayedexpansion
set n1=0
set n2=1
:loop
echo %n2%
set /a "n2=n1+n2" & set "n1=%n2%"
if %n2% gtr 0 goto loop
I am having problems with variables transferring throughout my batch file.
This is a rough example of what I have:
#echo off
setlocal enabledelayedexpansion
:one
set variableone=outputone
set variabletwo=outputtwo
set variablethree=outputthree
goto two
:two
set /a variable%variableone%four=numberone
set /a variable%variabletwo%five=numbertwo
set /a variable%variablethree%six=numberthree
goto three
:three
set /a variable%variableone%four+=(2*(!variable%variabletwo%five!-!!variable%variablethree%six!)
echo !variable%variableone%four!
exit
It is a lot longer than that and this is just a simplified version of what it actually is, however, the variables in the label ":three" won't transfer down so the variable ends up blank which leaves the equation blank as well. Is there a way to fix this?
It's tremendously difficult to see what you are doing.
In the below code, I've replaced the variable names NUMBER* with values.
I've also added the missing close-parenthesis and I'm wondering about the two successinve !
#ECHO OFF
setlocal enabledelayedexpansion
:one
set variableone=outputone
set variabletwo=outputtwo
set variablethree=outputthree
goto two
:two
set /a variable%variableone%four=numberone
set /a variable%variabletwo%five=numbertwo
set /a variable%variablethree%six=numberthree
set /a variable%variableone%four=14
set /a variable%variabletwo%five=25
set /a variable%variablethree%six=36
goto three
:three
set /a variable%variableone%four+=(2*(!variable%variabletwo%five!-!!variable%variablethree%six!))
echo !variable%variableone%four!
set var
Now for me, what is being echoed is -8 which is equal to 14+(2*(25-36))
So - works for me!