You are on page 1of 2

@echo off

:: to hide the contents and only display the output


setlocal enabledelayedexpansion
:: to have the same entries

title Daily Diary


:: displays the title when the bat file was opened

:menu
:: the contents below will be shown when the file was opened or more like the UI of
this program
cls
color b0
::to change the color
echo Daily Diary
echo.
:: echo with a dot is used when you want to display a blank space or black line
echo Select one of the following:
echo --------------------------------
echo ---- 1. Add Entry
echo ---- 2. View Entries
echo ---- 3. Exit
echo --------------------------------
:: the echo functions will display the text beside it
echo.
set /p "choice=Please type the number of your corresponding choice (1, 2, or 3): "
:: it allows the user to input a value and that value will be assigned to a
specific variable, which is the variable 'choice'

:: below are the conditions if the user inputs their choice


if "%choice%"=="1" goto add_entry
if "%choice%"=="2" goto view_entries
if "%choice%"=="3" ( goto end
) else ( goto menu
)
:: else condition if the user inputs a key that is not a number between 1 and 3
they will be sent back to the menu tab

:: this portion will be shown if the user inputs number 1


:add_entry
cls
echo Tell me about your day... (press Ctrl+Z then Enter to save):
set /p "entry="
if "%entry%"==" " ( goto menu
:: if the user inputs a blank space or accidentally presses the Enter button, they
will be headed back to the menu
) else (
echo %date% %time% - !entry! >> diary.txt
echo Entry saved...
pause>nul
:: same as the ordinary pause function, the only difference is that the text "press
any key" won't be shown
goto menu
)
:: the entry that the user inputs will be linked to the variable 'entry' and the
date, time, and the entry will be saved to an empty text file created separately

:: contents and commands that will be shown and executed if the user inputs number
2
:view_entries
cls
echo Diary Entries:
type diary.txt
:: automatically displays on the screen the entries that the user typed
pause>nul
goto menu

:: if the user inputs number 3, this will close the program


:end
endlocal

You might also like