Cool Batch Tricks - Part IV

Yo guys,

        I'm back again with Cool Batch Tricks – Part IV. It’s always better that you go serially.So go and check my previous posts if haven’t. 



It’s better that you see earlier parts as it will help you to understand the code.


So, Let’s start.   

Today, we will again learn two cool programs. They are :-


1.    Decimal TO Binary Converter :-

Yes, this programs converts Decimal Numbers to Binary Form.


Code:


@echo off
title Decimal To Binary Converter
color a
echo.
echo.
echo ---------------------------
echo Decimal To Binary Converter
echo ---------------------------
echo.
echo.
echo Enter a Decimal Number;
set /p a=Number:
set y=%a%
:BIN
set /a "x=%y%%%2%"
set f=%x%%f%
if %y%==1 goto out
set /a "y=y/2"
goto BIN
pause

:out
set f=0%f%
echo %f%
pause
exit





Output:

Converter 



          I won’t be explaining the lines I already explained in previous posts.

          In this program, we first get an input from the user & convert that number into Binary. We use ‘%’ symbol to show mod operation. We’ve used mod and division in a loop to convert the number. We’ve set the condition that when the input number becomes 1 then we come out of the loop. Then we display the eoutput in ‘f’ variable.

2.   Reminder

This program sets a reminder for a specified time. Actually this program is not perfected as Reminder should an a voice message. We’ll introduce how to add Voice to your Batch Scripts in upcoming parts.

Code:

@echo off
color a
:start
cls
title Reminder
echo.
echo.
echo ---------------Reminder-----------------
echo  Tell the time to remind at:
set /p a=Enter Time(24 hrs format: HH:MM[Very Strict]):
echo Give the reminder a Name(One word only)
set /p name=Name:
echo Enter the message to be displayed
set /p msg=Message:
:main
 if not exist %appdata%\Reminder md %appdata%\Reminder\
if exist %appdata%\Reminder\Rem.bat del %appdata%\Reminder\Rem.bat
set NULL=echo.
echo @echo off>>%appdata%\Reminder\Rem.bat
echo set NULL=echo. >>%appdata%\Reminder\Rem.bat
echo color a>>%appdata%\Reminder\Rem.bat
echo :start>>%appdata%\Reminder\Rem.bat
echo %NULL% >>%appdata%\Reminder\Rem.bat
echo echo Hey %username%, it is %a% .You,ve set the following Reminder.>>%appdata%\Reminder\Rem.bat
echo %NULL% >>%appdata%\Reminder\Rem.bat
echo echo REMINDER:%msg%>>%appdata%\Reminder\Rem.bat
echo %NULL%  >>%appdata%\Reminder\Rem.bat
echo %NULL%  >>%appdata%\Reminder\Rem.bat
echo pause >>%appdata%\Reminder\Rem.bat
echo del /Q %appdata%\Reminder\Rem.bat>>%appdata%\Reminder\Rem.bat
echo exit>>%appdata%\Reminder\Rem.bat



:confirm
echo The reminder named %name% will trigger at %a% giving message %msg%
echo Is everything Right??
echo 1. Yes
echo 2. No. Restart Again
set /p x=Choice:
if %x%==2 goto start
schtasks /create /st %a% /tn %name% /tr %appdata%\Reminder\Rem.bat   /sc once
echo.
echo.
title Reminder Set
echo ---------------Reminder Set-----------------
pause


Output:

Main program asking info

       
Reminder triggered at specified time

          

          Here, we’ve used the echo command with ‘>>’ and a directory with using the variable appdata. We can create another text file with the use of this. Here,first take all information from the user assign it to variable place them appropriately in desired places then we create another file namd ‘Rm.bat’. Then we use the schtasks command to trigger the file we just created at specified time. That’s it!!


Batch Files:                              1. DEC TO BIN Converter
                                                        2. Reminder(No voice)



So, these were the two programs of this tutorial. If you like this post please support us by sharing the post. Don't Forget to visit our Facebook & Instagram pages, If you want to contact us, write us at Remedyhub11@gmail.com & don’t forget to subscribe.