Hack Forums
[Shell] A semi-advanced parts shopping list - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] A semi-advanced parts shopping list (/showthread.php?tid=5832345)



A semi-advanced parts shopping list - Sir-Teabag - May 2, 2018

Okay so yesterday in IT class we were building PC's. Instead of using excel (which i hate) I decided to use something in batch like
Code
set /p part=
set /p cost =
echo %part% %cost% >>parts.txt

then I got extremely carried away and made this instead. It utilizes the 'type' command, to print the list in to another terminal which refreshes every two seconds or so.

Commands:
type 'listall' to list everything in the list without the price
type 'cls' to clear the list

^note you have to type it as the item name, then press enter twice for either of those to work.

You don't have to use it as a shopping list of course. I've got a few more project ideas that use the 'type' command in the same refreshing & %temp% methods used in this code. And since i'll probably never use this again after next week maybe someone here can.

code - https://pastebin.com/VBx6RyRU
(also note you can't use spaces for some reason)
[Image: dfc11c782476a629f5027d1ff8396131.gif]


RE: A semi-advanced parts shopping list - ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ - May 2, 2018

I actually think this is an excellent exercise.

Perhaps you may find it useful to use
Code
for /f "tokens=*" %%a in (parts.txt) do echo %%a

If you wanted to pick out certain elements from your list, this would be the way to do it. I'm not sure if you're comfortable with enableDelayedExpansion (or for loops), but it would be incredibly useful to you as you could really spruce up this code! (Not that there is anything wrong with it)

If you need any help, just ask.


RE: A semi-advanced parts shopping list - Sir-Teabag - May 2, 2018

(May 2, 2018 07:02 PM)ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ Wrote:  I actually think this is an excellent exercise.

Perhaps you may find it useful to use
Code
for /f "tokens=*" %%a in (parts.txt) do echo %%a

If you wanted to pick out certain elements from your list, this would be the way to do it. I'm not sure if you're comfortable with enableDelayedExpansion (or for loops), but it would be incredibly useful to you as you could really spruce up this code! (Not that there is anything wrong with it)

If you need any help, just ask.

Haha yeah thanks bro. I actually did think the
Code
for tokens
thing would've come in handy but i have absolutely no idea how to use it :(


RE: A semi-advanced parts shopping list - ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ - May 2, 2018

(May 2, 2018 07:11 PM)Sir-Teabag Wrote:  -snip-

This is a 4 line bit of code that will help you understand

Code
@echo off

rem Ever heard of a delimiter?
rem A delimiter (in this case it's a space by default) will tell
rem the loop to loop through both elements in the string instead of
rem just the string itself.
set "stringWithSpaces=Hello World"

for /f "tokens=1,2" %%a in ("%stringWithSpaces%") do (
    rem %%a is the first element separated by the space "Hello"
    echo %%a
    rem %%b is the second element separated by the space "World"
    echo %%b
)
pause



RE: A semi-advanced parts shopping list - Sir-Teabag - May 3, 2018

(May 2, 2018 08:19 PM)ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ Wrote:  This is a 4 line bit of code that will help you understand

Code
@echo off

rem Ever heard of a delimiter?
rem A delimiter (in this case it's a space by default) will tell
rem the loop to loop through both elements in the string instead of
rem just the string itself.
set "stringWithSpaces=Hello World"

for /f "tokens=1,2" %%a in ("%stringWithSpaces%") do (
rem %%a is the first element separated by the space "Hello"
echo %%a
rem %%b is the second element separated by the space "World"
echo %%b
)
pause

Hmm I think that makes sense..
Do you know any in-depth guides to this command?

Cheers :D


RE: A semi-advanced parts shopping list - Phlox - May 3, 2018

That's a very cool script @Sir-Teabag!


RE: A semi-advanced parts shopping list - ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ - May 3, 2018

(May 3, 2018 01:07 AM)Sir-Teabag Wrote:  Hmm I think that makes sense..
Do you know any in-depth guides to this command?

Cheers :D

Actually I do lol

https://hackforums.net/showthread.php?tid=3645708


RE: A semi-advanced parts shopping list - Sir-Teabag - May 3, 2018

(May 3, 2018 04:34 AM)ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ Wrote:  Actually I do lol

https://hackforums.net/showthread.php?tid=3645708

haha wow thank you very much! I'm sure this will come in handy soon