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.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 08-27-2009, 06: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
 


Similar Threads



© 2003-2025 Advameg, Inc.