Similar Code to mine why does it crash? I am trying to count the characters in TCode
set TCode=abnflgkASKGFJB
set /A Char=0
call :CheckCharacters 64
pause>nul
exit
:CheckCharacters
if defined TCode (
if "%TCode:~-1%"=="A" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="B" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="C" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="D" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="E" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="H" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="L" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="M" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="N" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="I" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="O" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="J" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="V" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="Q" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="R" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="U" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="W" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="T" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="S" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="P" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="F" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="G" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="Z" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="X" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="Y" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="K" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="a" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="b" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="c" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="d" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="e" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="h" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="l" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="m" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="n" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="i" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="o" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="j" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="v" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="q" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="r" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="u" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="w" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="t" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="s" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="p" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="f" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="g" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="z" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="x" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="y" set /a Char+=1 && goto CCFastForward:
if "%TCode:~-1%"=="k" set /a Char+=1
:CCFastForward
set "TCode=%TCode:~0,-1%"
goto CheckCharacters:
)
IF %Char% GEQ %~1 set CharLimitReached=True
set /A Char=0
goto eof:
Im not sure why it doesnt work maybe because of the IF statement I already tried it to change it or completly remove it still happens. Some Text otherwise im not able to post it because of to much code....
Related
I wanted to ask this question for a long time. When I echo for example a box using hashtags, and put inside some text, this happens:
https://i.stack.imgur.com/0VnZq.png
And without the text, it looks normal:
https://i.stack.imgur.com/jyOw7.png
So I made a moving system in batch, and when I opened it it ended up looking like this.
https://i.stack.imgur.com/ZUxf4.png
Here's the code, thank you very much if you find an answer and a fix for this.
#echo off
#title batch rpg
cls
color 0f
:initsetup
set xc=3
set yc=3
:displaysetup
cls
set X1Y1=
set X1Y2=
set X1Y3=
set X1Y4=
set X2Y1=
set X2Y2=
set X2Y3=
set X2Y4=
set X3Y1=
set X3Y2=
set X3Y3=
set X3Y4=
set X4Y1=
set X4Y2=
set X4Y3=
set X4Y4=
:SCREEN
set X%xc%Y%yc%=#
echo ....
echo .%X1Y4%%X2Y4%%X3Y4%%X4Y4%.
echo .%X1Y3%%X2Y3%%X3Y3%%X4Y3%.
echo .%X1Y2%%X2Y2%%X3Y2%%X4Y2%.
echo .%X1Y1%%X2Y1%%X3Y1%%X4Y1%.
echo ....
choice /c wasd /n
set choice=%ERRORLEVEL%
goto choice%choice%
:choice1
set /A yc=%yc%+1
if %yc% GTR 4 (
set /A yc=%yc%-1
goto displaysetup
) ELSE (
goto displaysetup
)
:choice2
set /A xc=%xc%-1
if %xc% LSS 1 (
set /A xc=%xc%+1
goto displaysetup
) ELSE (
goto displaysetup
)
:choice3
set /A yc=%yc%-1
if %yc% LSS 1 (
set /A yc=%yc%+1
goto displaysetup
) ELSE (
goto displaysetup
)
:choice4
set /A xc=%xc%+1
if %xc% GTR 4 (
set /A xc=%xc%-1
goto displaysetup
) ELSE (
goto displaysetup
)
The following code works for my problem but as you can see it is heavily protracted. So i was wondering if there was a more efficient way to find the largest of 6 given variables.
Code
#echo off
Set /a picture0 = 4
Set /a picture1 = 10
Set /a picture2 = 9
Set /a picture3 = 6
Set /a picture4 = 71
Set /a picture5 = 6
Set /a picture6 = 5
Call :TestPicture0
Call :TestPicture1
Call :TestPicture2
Call :TestPicture3
Call :TestPicture4
Call :TestPicture5
Call :TestPicture6
#pause
GoTo :EOF
So I have the six variables I want to use right, and I call each of them separately because they are rather long.
:TestPicture0
Set /a Test01 = %picture0% - %picture0%
Set /a Result01 = 0
Set /a Test02 = %picture0% - %picture2%
Set /a Result02 = 0
Set /a Test03 = %picture0% - %picture3%
Set /a Result03 = 0
Set /a Test04 = %picture0% - %picture4%
Set /a Result04 = 0
Set /a Test05 = %picture0% - %picture5%
Set /a Result05 = 0
Set /a Test06 = %picture0% - %picture6%
Set /a Result06 = 0
if %Test01% GEQ 0 (Set /a Result01 = 1)else (Set /a Result01 = 0)
if %Test02% GEQ 0 (Set /a Result02 = 1)else (Set /a Result02 = 0)
if %Test03% GEQ 0 (Set /a Result03 = 1)else (Set /a Result03 = 0)
if %Test04% GEQ 0 (Set /a Result04 = 1)else (Set /a Result04 = 0)
if %Test05% GEQ 0 (Set /a Result05 = 1)else (Set /a Result05 = 0)
if %Test06% GEQ 0 (Set /a Result06 = 1)else (Set /a Result06 = 0)
Set /a Picture0Final = %Result06% + %Result05% + %Result04% + %Result03% + %Result02% + %Result01%
If %Picture0Final% EQU 6 (Echo Picture Zero) Else (Echo no)
GoTo :EOF
:TestPicture1
Set /a Test10 = %picture1% - %picture0%
Set /a Result10 = 0
Set /a Test12 = %picture1% - %picture2%
Set /a Result12 = 0
Set /a Test13 = %picture1% - %picture3%
Set /a Result13 = 0
Set /a Test14 = %picture1% - %picture4%
Set /a Result14 = 0
Set /a Test15 = %picture1% - %picture5%
Set /a Result15 = 0
Set /a Test16 = %picture1% - %picture6%
Set /a Result16 = 0
if %Test10% GEQ 0 (Set /a Result10 = 1)else (Set /a Result10 = 0)
if %Test12% GEQ 0 (Set /a Result12 = 1)else (Set /a Result12 = 0)
if %Test13% GEQ 0 (Set /a Result13 = 1)else (Set /a Result13 = 0)
if %Test14% GEQ 0 (Set /a Result14 = 1)else (Set /a Result14 = 0)
if %Test15% GEQ 0 (Set /a Result15 = 1)else (Set /a Result15 = 0)
if %Test16% GEQ 0 (Set /a Result16 = 1)else (Set /a Result16 = 0)
Set /a Picture1Final = %Result16% + %Result15% + %Result14% + %Result13% + %Result12% + %Result10%
If %Picture1Final% EQU 6 (Echo Picture one) Else (Echo no)
GoTo :EOF
:TestPicture2
Set /a Test20 = %picture2% - %picture0%
Set /a Result20 = 0
Set /a Test21 = %picture2% - %picture1%
Set /a Result21 = 0
Set /a Test23 = %picture2% - %picture3%
Set /a Result23 = 0
Set /a Test24 = %picture2% - %picture4%
Set /a Result24 = 0
Set /a Test25 = %picture2% - %picture5%
Set /a Result25 = 0
Set /a Test26 = %picture2% - %picture6%
Set /a Result26 = 0
if %Test20% GEQ 0 (Set /a Result20 = 1)else (Set /a Result20 = 0)
if %Test21% GEQ 0 (Set /a Result21 = 1)else (Set /a Result21 = 0)
if %Test23% GEQ 0 (Set /a Result23 = 1)else (Set /a Result23 = 0)
if %Test24% GEQ 0 (Set /a Result24 = 1)else (Set /a Result24 = 0)
if %Test25% GEQ 0 (Set /a Result25 = 1)else (Set /a Result25 = 0)
if %Test26% GEQ 0 (Set /a Result26 = 1)else (Set /a Result26 = 0)
Set /a Picture2Final = %Result26% + %Result25% + %Result24% + %Result23% + %Result21% + %Result20%
If %Picture2Final% EQU 6 (Echo Picture Two) Else (Echo no)
GoTo :EOF
:TestPicture3
Set /a Test30 = %picture3% - %picture0%
Set /a Result30 = 0
Set /a Test31 = %picture3% - %picture1%
Set /a Result11 = 0
Set /a Test32 = %picture3% - %picture2%
Set /a Result32 = 0
Set /a Test34 = %picture3% - %picture4%
Set /a Result34 = 0
Set /a Test35 = %picture3% - %picture5%
Set /a Result35 = 0
Set /a Test36 = %picture3% - %picture6%
Set /a Result36 = 0
if %Test30% GEQ 0 (Set /a Result30 = 1)else (Set /a Result30 = 0)
if %Test31% GEQ 0 (Set /a Result31 = 1)else (Set /a Result31 = 0)
if %Test32% GEQ 0 (Set /a Result32 = 1)else (Set /a Result32 = 0)
if %Test34% GEQ 0 (Set /a Result34 = 1)else (Set /a Result34 = 0)
if %Test35% GEQ 0 (Set /a Result35 = 1)else (Set /a Result35 = 0)
if %Test36% GEQ 0 (Set /a Result36 = 1)else (Set /a Result36 = 0)
Set /a Picture3Final = %Result36% + %Result35% + %Result34% + %Result32% + %Result31% + %Result30%
If %Picture3Final% EQU 6 (Echo Picture Three) Else (Echo no)
GoTo :EOF
:TestPicture4
Set /a Test40 = %picture4% - %picture0%
Set /a Result40 = 0
Set /a Test42 = %picture4% - %picture2%
Set /a Result42 = 0
Set /a Test43 = %picture4% - %picture3%
Set /a Result43 = 0
Set /a Test41 = %picture4% - %picture1%
Set /a Result41 = 0
Set /a Test45 = %picture4% - %picture5%
Set /a Result45 = 0
Set /a Test46 = %picture4% - %picture6%
Set /a Result46 = 0
if %Test40% GEQ 0 (Set /a Result40 = 1)else (Set /a Result40 = 0)
if %Test42% GEQ 0 (Set /a Result42 = 1)else (Set /a Result42 = 0)
if %Test43% GEQ 0 (Set /a Result43 = 1)else (Set /a Result43 = 0)
if %Test41% GEQ 0 (Set /a Result41 = 1)else (Set /a Result41 = 0)
if %Test45% GEQ 0 (Set /a Result45 = 1)else (Set /a Result45 = 0)
if %Test46% GEQ 0 (Set /a Result46 = 1)else (Set /a Result46 = 0)
Set /a Picture4Final = %Result46% + %Result45% + %Result41% + %Result43% + %Result42% + %Result40%
If %Picture4Final% GEQ 6 (Echo Picture Four) Else (Echo no)
GoTo :EOF
:TestPicture5
Set /a Test50 = %picture5% - %picture0%
Set /a Result50 = 0
Set /a Test51 = %picture5% - %picture1%
Set /a Result51 = 0
Set /a Test52 = %picture5% - %picture2%
Set /a Result52 = 0
Set /a Test53 = %picture5% - %picture3%
Set /a Result53 = 0
Set /a Test54 = %picture5% - %picture5%
Set /a Result54 = 0
Set /a Test56 = %picture5% - %picture6%
Set /a Result56 = 0
if %Test50% GEQ 0 (Set /a Result50 = 1)else (Set /a Result50 = 0)
if %Test51% GEQ 0 (Set /a Result51 = 1)else (Set /a Result51 = 0)
if %Test52% GEQ 0 (Set /a Result52 = 1)else (Set /a Result52 = 0)
if %Test53% GEQ 0 (Set /a Result53 = 1)else (Set /a Result53 = 0)
if %Test54% GEQ 0 (Set /a Result54 = 1)else (Set /a Result54 = 0)
if %Test56% GEQ 0 (Set /a Result56 = 1)else (Set /a Result56 = 0)
Set /a Picture5Final = %Result56% + %Result54% + %Result53% + %Result52% + %Result51% + %Result50%
If %Picture5Final% EQU 6 (Echo Picture Five) Else (Echo no)
GoTo :EOF
:TestPicture6
Set /a Test60 = %picture6% - %picture0%
Set /a Result60 = 0
Set /a Test61 = %picture6% - %picture1%
Set /a Result61 = 0
Set /a Test62 = %picture6% - %picture2%
Set /a Result62 = 0
Set /a Test63 = %picture6% - %picture3%
Set /a Result63 = 0
Set /a Test64 = %picture6% - %picture6%
Set /a Result64 = 0
Set /a Test65 = %picture6% - %picture6%
Set /a Result65 = 0
if %Test60% GEQ 0 (Set /a Result60 = 1)else (Set /a Result60 = 0)
if %Test61% GEQ 0 (Set /a Result61 = 1)else (Set /a Result61 = 0)
if %Test62% GEQ 0 (Set /a Result62 = 1)else (Set /a Result62 = 0)
if %Test63% GEQ 0 (Set /a Result63 = 1)else (Set /a Result63 = 0)
if %Test64% GEQ 0 (Set /a Result64 = 1)else (Set /a Result64 = 0)
if %Test65% GEQ 0 (Set /a Result65 = 1)else (Set /a Result65 = 0)
Set /a Picture6Final = %Result65% + %Result64% + %Result63% + %Result62% + %Result61% + %Result60%
If %Picture6Final% EQU 6 (Echo Picture Six) Else (Echo no)
GoTo :EOF
If yall know a way to make this better please let me know :D----<-<
*Edit: fixed some 0's to ones ... literally
you asked how to
find the largest of 6 given variables
There is no need to minus each and compare the result to 0. It isn't even neccessary to compare the variables.
#echo off
====SETLOCAL EnableDelayedExpansion EnableExtensions
set/a"picture0=4,picture1=10,picture2=9,picture3=6,picture4=71,picture5=6,picture6=5,MAX=0"
FOR /L %%# in (0 1 6) do if !picture%%#! GTR !max! set/a"max=!picture%%#!,max_var=%%#"
echo MAX is picture%max_var%=%max%
Limitations:
If %picture3% == %picture4% == 6, %max% will be picture3.
Works for 32-bits integers only. See Windows batch file IF failure - How can 30000000000000 equal 40000000000?
In this case, because the variables are in a "list", I used a FOR /L loop . But in case it's not, use FOR.
An alternative to #HackingAddict1337's answer:
A For /F loop using the Set command in conjunction with the Array variable prefix can be used to retrieve the highest value withought needing to know / reference the size of the Array:
Setlocal ENABLEdelayedexpansion
For /F "Tokens=1,2 Delims==" %%A in ('Set picture') Do If "!Max!" == "" (Set "Max=%%B" & Set "MaxV=%%A") Else If %%B GTR !Max! (Set "Max=%%B" & Set "MaxV=%%A")
I have received the below errors during the execution:
main.sh: line 9: syntax error near unexpected token (' main.sh: line
9:if %s3% LSS 0 ( '
Please have a look at the sample code:
#echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set /a s1=10
set /a s2=20
set /a Var=0
set /a s3= %s1% - %s2%
if %s3% LSS 0 (
set s3=%s2%-%s1%
SET /a Var= (%s3%/%s1)*100
) else (
SET /a Var= (%s3%/%s2%)*100
)
pause
if "%Var%" GTR 15 goto failure
:failure
echo %Var%
pause
This is the way I would do it, that is, this code get the same result:
#echo off
SETLOCAL
set /a "s1=10, s2=20, Var=0, s3= s1 - s2, s3LSS0 = -(s3>>31)"
set /a "s3 = s3LSS0*(s2-s1) + !s3LSS0*s3, Var = (s3 / (s3LSS0*s1 + !s3LSS0*s2) )*100"
if %Var% GTR 15 goto failure
echo Ok: %Var%
pause
goto :EOF
:failure
echo Failure: %Var%
pause
Ive been working on this decimal to hexadecimal and binary converter, the hexadecimal converts the decimal number into hex, and the binary converter does it's job.
This works just fine, but is there a different way to implement this code?
#echo off
setlocal EnableDelayedExpansion
:Main
setlocal
cls
set /p decIn=enter Decimal value:
call :DectoHex %decIn% hexOut
call :DectoBin %decIn% binOut
echo !hexOut!
echo !binOut!
pause>nul
goto :main
endlocal
::-------------------------------------------------------------------------------------
:DectoHex
set /a A=%1
set map=0123456789ABCDEF
set H=
:Hexloop
set /a B=!A! %%16 & set /a A /=16
set H=!map:~%B%,1!!H!
if !A! gtr 0 goto :Hexloop
set %2=!H!
goto :eof
::-------------------------------------------------------------------------------
:DectoBin
:: Note Dec Bit Bin (DBB)
set /a Dec=%1
set Bin=
for /L %%i in (1,1,32) do (
set /a "Bit=Dec&1, Dec>>=1"
set Bin=!Bit!!Bin!
)
:skimming
if %Bin:~0,1% == 0 (
set Bin=%Bin:~1% & goto :skimming
)
set %2=!Bin!
goto :eof
::-----------------------------------------------------------------------------
:BintoDec
set bin=11011
set dig=
set digval=1
set dec=
:Loop
if %bin% gtr 1 (
set dig=%bin:~-1%
set bin=%bin:~0,-1%
) else (
set /a dig=%bin%
set bin=0
)
if %dig% equ 1 (
set /a dec+=%digval%
)
set digval *=2
if %bin% gtr 0 goto :loop
echo %dec%
pause>nul
goto :eof
The main function recieves an input from the user and passes the variable as a parameter to a hexadecimal converter and a binary converter, the
To convert to/from any number base between 2 and 36:
:: Q:\Test\2017\09\16\SO_46254352.cmd
#echo off & setlocal EnableDelayedExpansion
set map=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
:Main
cls
set "DecIn="
set /p DecIn=enter value:
if not defined DecIn goto :Eof
Set /A DecIn=DecIn
call :Dec2Base 2 %DecIn% BaseOut
call :Base2Dec 2 %BaseOut% DecBack
echo DecBack=%DecBack% Base 2=%BaseOut%
call :Dec2Base 16 %DecIn% BaseOut
call :Base2Dec 16 %BaseOut% DecBack
echo DecBack=%DecBack% Base 16=%BaseOut%
call :Dec2Base 32 %DecIn% BaseOut
call :Base2Dec 32 %BaseOut% DecBack
echo DecBack=%DecBack% Base 32=%BaseOut%
goto :main
::-------------------------------------------------------------------------------------
:Dec2Base Base DecIn BaseOut
Setlocal
Echo:%2|findstr /i "^[%map:~0,10%]*$" >Nul 2>&1 ||(Echo invalid char for base 10&Goto :Eof)
set /a Num=%2
set "Ret="
:Dec2BaseLoop
set /a "Digit=Num %% %1"
set /a "Num /= %1"
set Ret=!map:~%Digit%,1!%Ret%
if "%Num%" neq "0" goto :Dec2BaseLoop
Endlocal&Set "%3=%Ret%"&Goto :Eof
::-------------------------------------------------------------------------------------
:Base2Dec Base BaseIn DecBack
Setlocal EnableDelayedExpansion
Set /A "Base=%1,PlaceVal=1,Ret=0"
Echo:%2|findstr /i "^[!map:,%Base%!]*$" >Nul 2>&1 ||(Echo invalid char for base %1&Goto :Eof)
Set Val=%2
:Base2DecLoop
Set "Digit=%Val:~-1%"
If %Digit% Leq 9 goto :Next
For /L %%i in (10,1,%Base%) Do If /i "!Digit!" Equ "!map:~%%i,1!" (Set "Digit=%%i" & Goto :Next )
Echo Something went wrong & Pause
:Next
set /A "Ret+=Digit * PlaceVal,PlaceVal *= Base"
Set "Val=%Val:~0,-1%"
If defined Val goto :Base2DecLoop
Endlocal & Set "%3=%Ret%" & Goto :Eof
Sample output:
> Q:\Test\2017\09\16\SO_46254352.cmd
enter value: 4095
DecBack=4095 Base 2=111111111111
DecBack=4095 Base 16=FFF
DecBack=4095 Base 32=3VV
enter value: 0xBadAffe
DecBack=195932158 Base 2=1011101011011010111111111110
DecBack=195932158 Base 16=BADAFFE
DecBack=195932158 Base 32=5QRBVU
In a function, it gaves that.
(Put in in a UTF-8 .txt file with BOM EFBBBF, first line must be blank)
cls
#echo off
cd /d "%~dp0"
chcp 65001 >nul
set title_script=Base conversion
title %title_script%
set "decimal_number=200"
set "result_hexadecimal="
call :function_change_base_number 10 decimal_number 16 result_hexadecimal
echo %decimal_number% base 10 = %result_hexadecimal% base 16
echo.
set "octal_number=310"
set "result_binary="
call :function_change_base_number 8 octal_number 2 result_binary
echo %octal_number% base 8 = %result_binary% base 2
echo.
set "quaternary_number=3020"
set "base_36_result="
call :function_change_base_number 4 quaternary_number 36 base_36_result
echo %quaternary_number% base 4 = %base_36_result% base 36
echo.
pause
exit
:function_change_base_number
setlocal enabledelayedexpansion
set /a input_base=%~1
set input_number=!%~2!
set /a output_base=%~3
rem UCase
for %%i in ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I" "j=J" "k=K" "l=L" "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R" "s=S" "t=T" "u=U" "v=V" "w=W" "x=X" "y=Y" "z=Z") do (
call set "input_number=!input_number:%%~i!"
)
set map=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
set map_base=!map:~0,%input_base%!
set /a position=0
set input_number_check=%input_number%
:loop_1
set current_map_base_character=!map_base:~%position%,1!
set input_number_check=!input_number_check:%current_map_base_character%=!
if "!input_number_check!" == "" goto next_1
set /a position+=1
if "!map_base:~%position%,1!" NEQ "" goto loop_1
echo Error.
echo Invalid character in base %input_base%.
echo.
pause
exit
:next_1
set /a carry_flag=1
set "input_number_tmp=%input_number%"
set "result_decimal="
:loop_2
set "input_number_tmp_digit=%input_number_tmp:~-1%"
if %input_number_tmp_digit% LEQ 9 goto next_2
for /l %%i in (10,1,%input_base%) do (
if /i "%input_number_tmp_digit%" EQU "!map:~%%i,1!" (
set "input_number_tmp_digit=%%i"
goto :next_2
)
)
echo Error.
:next_2
set /a result_decimal+=input_number_tmp_digit * carry_flag
set /a carry_flag *= input_base
set "input_number_tmp=%input_number_tmp:~0,-1%"
if defined input_number_tmp goto :loop_2
set /a input_number_tmp=%result_decimal%
set "result="
:loop_3
set /a "division_remainder=input_number_tmp %% !output_base!"
set /a "input_number_tmp /= !output_base!"
set result=!map:~%division_remainder%,1!%result%
if "%input_number_tmp%" NEQ "0" goto loop_3
endlocal & set %~4=%result%
goto :eof
I couldn't get %difference_two% to work It can find %difference_one% as 2 but when I make it divide 2 by 2 it doesn't display as anything.
Use the numbers 2,5,10,17,26
To get what I need.
#echo off
color 0a
title Solver
:numbers
cls
set /p first=First:
set /p second=Second:
set /p third=Third:
set /p fourth=Fourth:
set /p fifth=Fifth:
goto solve
:solve
cls
set /a second_minus_first= %second% - %first%
set /a third_minus_second= %third% - %second%
if %third_minus_second%==%second_minus_first% (
goto s
) else (
goto d
)
:d
cls
set /a fourth_minus_third= %fourth% - %third%
set /a difference= %third_minus_second% - %second_minus_first%
set /a difference_one= %fourth_minus_third% - %third_minus_second%
if %difference%==%difference_one% (
set /a difference_two= %difference_one% / 2
set /a thing= %first% - %difference_two%
cls
echo %difference_two%n Squared + %thing%
pause >nul
goto numbers
) else (
goto wrong
)
Try this:
#echo off
setlocal EnableDelayedExpansion
color 0a
title Solver
:numbers
cls
set /p first=First:
set /p second=Second:
set /p third=Third:
set /p fourth=Fourth:
set /p fifth=Fifth:
goto solve
:solve
cls
set /a second_minus_first= %second% - %first%
set /a third_minus_second= %third% - %second%
if %third_minus_second%==%second_minus_first% (
goto s
) else (
goto d
)
:d
cls
set /a fourth_minus_third= %fourth% - %third%
set /a difference= %third_minus_second% - %second_minus_first%
set /a difference_one= %fourth_minus_third% - %third_minus_second%
if %difference%==%difference_one% (
set /a difference_two= !difference_one! / 2
set /a thing= !first! - !difference_two!
cls
echo !difference_two!n Squared + !thing!
pause >nul
goto numbers
) else (
goto wrong
)
In batch, commands in a code block (between ( )) are interpreted as on the same line, so you need to use setlocal EnableDelayedExpansion and use ! instead of % inside them.