Data Gatherer - nsevyd - Aug 28, 2015
Hey guys,
Its me again, some of you may already know that I am new to batch and may have seen my other post on the text game I made, I got very positive feedback so I decided to upload this which I just finished making π
So this one contains two batch files. One of them is a Data Gatherer which will gather data and store it in a new text file which is stored in a new directory. This is the one you want to run first. The second one is a data reader and this contains an interactive menu with multiple options. With this one when you enter the Users Name it will display there data previously created with the last batch file. The code is below π
This is the Data Gatherer.
Code @echo off
set /p userForename=What is your forename:
cls
set /p userSurname=What is your surname:
cls
set /p userJobTitle=What is your current job title:
cls
set /p userSalary=What is your current salary:
cls
set /p userPeriod=How many months have you been working at your current job:
cls1
MKDIR UserData1
CD UserData
echo Forename: %userForename% > %userForename%%userSurname%Data.txt
echo Surname: %userSurname% >> %userForename%%userSurname%Data.txt
echo Job Title: %userJobTitle% >> %userForename%%userSurname%Data.txt
echo Salary: $%userSalary% >> %userForename%%userSurname%Data.txt
echo Current working period: %userPeriod% Months >> %userForename%%userSurname%Data.txt
This is the Data Reader.
Code @echo off
:menu
cls
echo -----------
echo Data Reader
echo -----------
echo 1. Read Data
echo 2. Options
echo 3. Close
echo.
set /p menuChoice=
if %menuChoice% == 1 goto :readData
if %menuChoice% == 2 goto :Options
if %menuChoice% == 3 exit (
) else (
echo.
echo Please enter a valid option...
pause >nul
goto :menu
)
:readData
CD UserData
cls
set /p userForename= Enter users forename:
set /p userSurname= Enter users surname:
(
set /p line1=
set /p line2=
set /p line3=
set /p line4=
set /p line5=
) < %userForename%%userSurname%Data.txt
cls
echo %userForename% %userSurname%'s Data:
echo.
echo %line1%
echo %line2%
echo %line3%
echo %line4%
echo %line5%
echo.
echo Press ^<enter^> to return to the menu...
pause >nul
goto :menu
:Options
cls
echo ----------
echo Text Color
echo ----------
echo 1. Blue
echo 2. Green
echo 3. Aqua
echo 4. Red
echo 5. Purple
echo 6. Yellow
echo 7. White
echo 8. Grey
echo 9. Light Blue
echo A. Light Green
echo B. Light Aqua
echo C. Light Red
echo D. Light Purple
echo E. Light Yellow
echo F. Bright White
echo.
set /p colorChoice= Select a color:
if %colorChoice% == 1 (
color 01
cls
echo Color has been changed to Blue
)
if %colorChoice% == 2 (
color 02
cls
echo Color has been changed to Green
)
if %colorChoice% == 3 (
color 03
cls
echo Color has been changed to Aqua
)
if %colorChoice% == 4 (
color 04
cls
echo Color has been changed to Red
)
if %colorChoice% == 5 (
color 05
cls
echo Color has been changed to Purple
)
if %colorChoice% == 6 (
color 06
cls
echo Color has been changed to Yellow
)
if %colorChoice% == 7 (
color 07
cls
echo Color has been changed to White
)
if %colorChoice% == 8 (
color 08
cls
echo Color has been changed to Grey
)
if %colorChoice% == 9 (
color 09
cls
echo Color has been changed to Light Blue
)
if %colorChoice% == a (
color 0a
cls
echo Color has been changed to Light Green
)
if %colorChoice% == b (
color 0b
cls
echo Color has been changed to Light Aqua
)
if %colorChoice% == c (
color 0c
cls
echo Color has been changed to Light Red
)
if %colorChoice% == d (
color 0d
cls
echo Color has been changed to Light Purple
)
if %colorChoice% == e (
color 0e
cls
echo Color has been changed to Light Yellow
)
if %colorChoice% == f (
color 0f
cls
echo Color has been changed to Bright White
)
echo.
echo Press ^<enter^> to return to the menu...
pause >nul
goto menu
Please leave feedback and also I don't mind anyone using this code so use it as you wish π
* - 'Palladium - Aug 29, 2015
Very nice code for a beginner, keep it up and maybe script some more "useful" applications. No hard feelings.
* - Mr Robot. - Aug 29, 2015
When reading data, it gives an "ECHO IS OFF" error.
Try removing @echo off in the second one.
* - Ventriloquism - Aug 29, 2015
(Aug 28, 2015 08:04 PM)nsevyd Wrote: Please leave feedback...
Alrighty π
Not saying that this method is better, but is one of my good favorites:
Code @echo off >Nul
Set "txtfile=Data.txt"
set/p "a=What is your forename: "
set/p "b=What is your surname: "
set/p "c=What is your current job title: "
set/p "d=What is your current salary: "
set/p "e=How many months have you been working at your current job: "
REM =-=-=-=-=-=-=-=-=-=-=
echo Forename: %a% >Data.txt
echo Surname: %d% >>Data.txt
echo Job Title: %c% >>Data.txt
echo Salary: %d% >>Data.txt
echo Work Period: %e% >>Data.txt
REM =-=-=-=-=-=-=-=-=-=-=
cls
For /f "delims=" %%a in (%txtfile%) do (
echo %%a
)
pause >nul
@exit /b
By using that FOR Statement, if will automatically echo everything in the textfile...possibly eliminating unnecessary code.
Thought it might make your life easier. Idk π€
* - nsevyd - Aug 29, 2015
(Aug 29, 2015 07:19 AM)RΞΏuterΞelter Wrote: Alrighty π
Not saying that this method is better, but is one of my good favorites:
Code @echo off >Nul
Set "txtfile=Data.txt"
set/p "a=What is your forename: "
set/p "b=What is your surname: "
set/p "c=What is your current job title: "
set/p "d=What is your current salary: "
set/p "e=How many months have you been working at your current job: "
REM =-=-=-=-=-=-=-=-=-=-=
echo Forename: %a% >Data.txt
echo Surname: %d% >>Data.txt
echo Job Title: %c% >>Data.txt
echo Salary: %d% >>Data.txt
echo Work Period: %e% >>Data.txt
REM =-=-=-=-=-=-=-=-=-=-=
cls
For /f "delims=" %%a in (%txtfile%) do (
echo %%a
)
pause >nul
@exit /b
By using that FOR Statement, if will automatically echo everything in the textfile...possibly eliminating unnecessary code.
Thought it might make your life easier. Idk π€
Thanks for showing me how I can implement the for statement into my code π Learnt something new today π
* - Ventriloquism - Aug 29, 2015
(Aug 29, 2015 11:38 AM)nsevyd Wrote: Thanks for showing me how I can implement the for statement into my code π Learnt something new today π
I just figured it would save you some time π€
* - Advertisement - Aug 29, 2015
(Aug 29, 2015 12:28 PM)RΞΏuterΞelter Wrote: I just figured it would save you some time π€
Would tokens=* not be more efficient
* - Ventriloquism - Sep 1, 2015
(Aug 29, 2015 03:04 PM)Harima Wrote: Would tokens=* not be more efficient
Well for one thing, delimiters are the shit π And I guess it might...how would you do it?
* - annikk.exe - Sep 1, 2015
An alternative to For /f "delims=" is For /f "tokens=*"
They both have the effect of chucking the entire line of text into the first token.
They are both just as effective as each other, but on balance I prefer "delims=" because it's 1 character less. :P
* - Ventriloquism - Sep 1, 2015
(Sep 1, 2015 08:04 AM)annikk.exe Wrote: An alternative to For /f "delims=" is For /f "tokens=*"
They both have the effect of chucking the entire line of text into the first token.
They are both just as effective as each other, but on balance I prefer "delims=" because it's 1 character less. :P
That's what I thought. This is another reason why delimiters are simply the best π
|