Functions?

J

Joe

I am a Newbie so be gentle please with the tech...

With that over, I would LIKE to create a function (similar
to C++) in a batch file so I dont have to call out to
other batch files and have a myriad of calls and files to
deal with, and I was wondering what I need to go about it.

Joe
 
P

Phil Robyn

Joe said:
I am a Newbie so be gentle please with the tech...

With that over, I would LIKE to create a function (similar
to C++) in a batch file so I dont have to call out to
other batch files and have a myriad of calls and files to
deal with, and I was wondering what I need to go about it.

Joe

What is your function supposed to do?
 
R

Ray at

If I understand what you mean, here's a way.


func.bat:
goto %1
:a
net send ray hi
goto :eof

:b
net send ray bye
goto :eof


Then you can execute:
func a
func b

etc.


Self important Ray at work
 
A

Al Dunbar [MS-MVP]

My guess is that the OP simply wants to avoid the hassle of maintaining code
in separate files. Your func.bat certainly reduces the number of files
involved, but perhaps he does not know that this could all go in one file
using internal subroutines, i.e.:

@echo off
echo/program to demonstrate internal functions
call:showusername
call:getinput zzz "enter a zzz value: "
echo/you entered [%zzz%]
goto:eof

:showusername
echo/%username%
goto:eof

:getinput
set /p %1=%2
goto:eof

None of these are "functions" in the purest sense, as there is no way to
reference the calls as values, as is the case with C++ and other languages
supporting functions, i.e.:

result = atan(angle)

The ":getinput" routine uses a technique I have found useful, where you
supply the name of the variable you want the result assigned to. This is
more general than hard-coding a variable name in the routine, and then
remembering to use it when the routine is called, as you typically wind up
having more SET commands.

The above simple technique could also be used in a separate function library
file as suggested by Ray at {wherever he is}.


/Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top