Batch Programming - Music Banter Music Banter

Go Back   Music Banter > Community Center > The Lounge
Register Blogging Today's Posts
Welcome to Music Banter Forum! Make sure to register - it's free and very quick! You have to register before you can post and participate in our discussions with over 70,000 other registered members. After you create your free account, you will be able to customize many options, you will have the full access to over 1,100,000 posts.

Reply
 
Thread Tools Display Modes
Old 08-27-2009, 07:00 AM   #1 (permalink)
Juicious Maximus III
 
Guybrush's Avatar
 
Join Date: Nov 2008
Location: Scabb Island
Posts: 6,525
Default Batch Programming

Okay, okay - I realize I probably couldn't have made a more nerdy thread and I guess it's doomed to die an embarassing death, but I was wondering, have or do anyone else here do any batch programming?

Yes, it's pretty weak as far as programming go and yes, there's not much you can do with it but I used to play around with it as a kid (started with fiddling around in the autoexec.bat) and so I picked it up again a couple of years ago to see if I could do something interesting with it. Once I got my imagination going, it seems I could.

The very easiest though perhaps not the most useful thing I wrote was this little thing which generates a random number between 1 and whatever value you want.

Code:
@echo off
if "%1"=="" goto missing
if "%1"=="?" goto missing
if "%1"=="/?" goto missing

:random
set /a trandom=(%random%*%1/32768)+1
goto result

:missing
echo.
echo This file generates random numbers from 1 to the number you define.
echo.
echo To define a number, as an example - just write like this : "tdrandom 6".
echo That gives you a random number between 1 and 6.
echo.
echo You can edit this file and remove the last line if you want to keep 
echo the random variable in the memory for use with other files.
echo.
echo -- Tore
goto end

:result
echo.
echo Result = %trandom%

:end
set trandom=
(%1 means the first command line argument and %random% means a number between 1 and 32767 or something)

For windows people, if you want to try it, just copy and paste this into a text file, save it as whatever.bat (changing the filetype to "bat" rather than "txt")and then click the start menu, choose run and write "cmd" in the box and press enter. You will open the command prompt. Navigate to where the file is and write the filename, that will run it.

This is of course the simplest thing I did, I've advanced beyond this and I found that there are some charming features to this old batch stuff. I especially like the way you can do for-loops (I can post examples later on)!

So, anyone else here who have fiddled around with this ancient art? :p
__________________
Something Completely Different
Guybrush is offline   Reply With Quote
Old 08-27-2009, 10:39 AM   #2 (permalink)
Partying on the inside
 
Freebase Dali's Avatar
 
Join Date: Mar 2009
Posts: 5,584
Default

Yea that reminds me of Qbasic programming back in the day. We used to mess with batch programming as an aside and make what you'd basically call macros to make quick work of repetetive actions.
I started getting into dos-based scripting but eventually moved away from it.
Now that I'm taking a VisualBasic programming class in college, I'll probably start messing with this type of stuff again, but more along the VB and C++ lines.
__________________
Freebase Dali is offline   Reply With Quote
Old 08-27-2009, 02:47 PM   #3 (permalink)
Juicious Maximus III
 
Guybrush's Avatar
 
Join Date: Nov 2008
Location: Scabb Island
Posts: 6,525
Default

The only "real" programming I've done besides this is php which is rather useful I find. Batch is just for fun of course. A funny thing about batch is the way you can divide your code into different sections and then jump to the different ones using the goto command. You can also use that in order to create for-oops ..

Code:
:start
@echo off
set /a var="1"
echo.

:loop
echo %var%
set /a var=%var%+1
if "%var%"=="101" goto end
goto loop

:end
set var=
This script would list numbers from 1 to 100, each on a separate line (set defines a variable - /a that it's a numerical value, echo outputs something to screen, goto jumps to different sections in the script and if runs a command when the if-criteria is met).

In the above example, there's an if-argument that when fulfilled jumps to the end of the script .. But if it's criteria is not met, the "goto loop" command will run instead, making the program run through the loop section one more time. I think it's a quite charming and intuitive way of doing it
__________________
Something Completely Different
Guybrush is offline   Reply With Quote
Old 08-27-2009, 03:15 PM   #4 (permalink)
Partying on the inside
 
Freebase Dali's Avatar
 
Join Date: Mar 2009
Posts: 5,584
Default

That's pretty much how Qbasic runs. Each instructional line is given a numerical address and you assign a result with the GOTO command by listing the numerical address of the desired code. Eg.. "IF Y = 1 GOTO 15".

But yea.. I wouldn't set about trying to learn Basic this late in the game. C sharp and C++ is pretty much the standard for programmers, and Visual Basic for developers. VB macros kick more ass than console code anyhow.
__________________

Last edited by Freebase Dali; 09-01-2009 at 01:17 PM.
Freebase Dali is offline   Reply With Quote
Old 08-31-2009, 06:14 PM   #5 (permalink)
 
Zer0's Avatar
 
Join Date: Sep 2007
Location: Ireland
Posts: 3,792
Default

I've never done batch programming. I'm pretty experienced in JAVA, 8051 chip assembly code, VHDL code and some C code. I learned JAVA as my main programming language instead of C++ which is a bit of a pain in the balls as regards job opportunities.

That code looks very similar to chip assembly code so i can kinda work out what's going on.
In the second set of code a variable is set to '1'.
The loop then increments the variable by 1
When the variable gets to '101' it breaks the loop
__________________
Zer0 is offline   Reply With Quote
Old 08-31-2009, 09:49 PM   #6 (permalink)
Fish in the percolator!
 
Seltzer's Avatar
 
Join Date: Dec 2005
Location: Hobbit Land NZ
Posts: 2,870
Default

I haven't done that much batch programming in DOS - I've spent more time doing BASH stuff in Linux. But DOS and batch programming shouldn't be underestimated... Back in high school I was trying to gain access to a local hard drive and there were all these fancy security restrictions in place so that only network drives could be opened. As soon as you opened C in explorer, the window would close and iirc, local drives were protected from basic DOS browsing etc. But I was able to gain access by opening DOS and typing subst z: c:\ which creates a completely unrestricted virtual Z drive mirroring the contents of c:. That's what they get for ignoring low level DOS security.


Dijkstra once said that it's almost impossible to teach good programming to students who have had prior exposure to BASIC and as potential programmers they are mentally mutilated beyond hope of regeneration. Well I hope not because QBasic was my first language.

Anyway I'm familiar with C, C#, Java, MATLAB, TCL/TK, SQL, AVR and MIPS assembly. I'm learning C++ now because a guy in my class recommended I apply for a job at the forklift robotics firm where he manages a few interns, and C++ is the lingua franca there. I'd like to learn Python and PHP at some point in the future.

My next personal project is to write a basic operating system but I have no idea when I'll get started because I'm quite busy atm. I'd love to do it for my fourth year project next year so that I have an excuse to spend all my time on it... but knowing the university, they'd sooner have me do choose some unnecessarily academic and pointless project from a pre-defined list. I know I'd learn a hell of a lot more from writing an OS than doing some fruitless vapid Java project.
__________________
Seltzer is offline   Reply With Quote
Old 09-01-2009, 02:44 AM   #7 (permalink)
Juicious Maximus III
 
Guybrush's Avatar
 
Join Date: Nov 2008
Location: Scabb Island
Posts: 6,525
Default

Hehe, I started making a fighting fantasy game in batch (based on the the real thing, Steve Jackson and Ian Livingstone's "The Warlock of Firetop Mountain" from 1982) .. in which you play a character that has certain ability scores, pick up inventory and fights monsters along the way as he progresses through a dungeon.

[img]http//org/1.jpg[/img]



It's good enough for that at least Rather lengthy project though, so many rooms to write (~350)!
__________________
Something Completely Different
Guybrush is offline   Reply With Quote
Old 09-01-2009, 01:21 PM   #8 (permalink)
Partying on the inside
 
Freebase Dali's Avatar
 
Join Date: Mar 2009
Posts: 5,584
Default

LOL... Tore that's awesome.

I used to do that in QB too.
I remember trying to even do graphic interactions but I could never work out the code right. There used to be all kinds of code snipplets for different functions that I used to scour on the net and try to use, but I think I was setting my goals unreasonably high when I set out to make a Mortal Kombat remake... lol.. Yea that ended up consisting of "press any key to continue..." then a random flash of colors and an odd looking brown formation, then a blue screen.
__________________
Freebase Dali is offline   Reply With Quote
Old 09-01-2009, 07:49 PM   #9 (permalink)
nothing
 
mr dave's Avatar
 
Join Date: Mar 2008
Location: everywhere
Posts: 4,315
Default

Quote:
Originally Posted by toretorden View Post
Hehe, I started making a fighting fantasy game in batch (based on the the real thing, Steve Jackson and Ian Livingstone's "The Warlock of Firetop Mountain" from 1982) .. in which you play a character that has certain ability scores, pick up inventory and fights monsters along the way as he progresses through a dungeon.





It's good enough for that at least Rather lengthy project though, so many rooms to write (~350)!
that looks AWESOME!

please please please hook us up when you're done.
__________________
i am the universe

Quote:
Originally Posted by bandteacher1 View Post
I type whicked fast,
mr dave is offline   Reply With Quote
Old 09-02-2009, 04:11 AM   #10 (permalink)
Juicious Maximus III
 
Guybrush's Avatar
 
Join Date: Nov 2008
Location: Scabb Island
Posts: 6,525
Default

Quote:
Originally Posted by mr dave View Post
that looks AWESOME!

please please please hook us up when you're done.
Haha, thanks! If I ever finish it, I will

The reason I'm making it is I played that game in it's book form when I was a kid and I recently found it again on a flea market, but the book was badly tattered. Every time I look in it, more pages come loose, so why not write it up as a game instead?

This is the book!

__________________
Something Completely Different
Guybrush is offline   Reply With Quote
Reply


Similar Threads



© 2003-2024 Advameg, Inc.