Can I pass paramters to another program from VB???

Is it possible to pass a parameter to another program from a vb program?

What I want to do is go into a vb program, select a directory, click OK. When I click OK, I want the vb program to pass the directory parameter to a Perl script(, which will then do the rest.Does anyone know how to do this?
Who is Participating?
mark2150Connect With a Mentor Commented:
The Perl script you're firing is *NOT* a program. You need to run the Perl *EXECUTABLE* and pass *IT* the D:\resources\ " & strPath as it's parameter. Since NOTEPAD is an EXE file, it works OK.

This is not a problem with VB all depend on the program you call does it accept parameters or not, in VB you could call other programm and send parameters if you want but if the other part can accept parameter.

hobsterAuthor Commented:
Can you provide some sample code? Thank you.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Command line parameters are usually the easiest way if your child program understands them. Then you can use a SHELL statement to fire the child task similar to:

SHELL( "child.exe parameters go here"), 1

hobsterAuthor Commented:
Sorry, I have to do this from within my vb application.
umm... in mark2150's answer, you *are* calling it from within your vb app...

if you don't want to see the shell window, you can pass parms to that effect, but what you're asking to do is to start the perl interpreter on your  of course, SHELL runs async to you, so it'll return before the perl script completes...

i sense that there's more to your requirement than meets the eye; what's the perl script doing? why the requirement that 'vb runs the perl script'? what exactly do you mean by that?
hobsterAuthor Commented:
I'm sorry. I'm such an idiot. You're absolutely right.

One problem though. I can call notepad (1 parameter) from within the vb application. But when I did the following for the perl script, it gave me an error. Note, the Shell has 2 parameters. I think that's where the problem is.

Private Sub cmdOK_Click()

   Dim strPath As String
   Dim RetVal As Variant
   strPath = dirFolder.Path

   'pass Perl script and folder path
   RetVal = Shell("D:\resources\ " & strPath, 1)

   'it works with notepad
   'RetVal = Shell("C:\Winnt\Notepad.exe", 1)
End Sub
I have problems with passing "LONG" parms.


exefile = "C:\xxxxxx\ccccc\xxxxx.EXE"
p1 = " C:\xxxxxx\yyyyyy\zzzzz\aaaa.txt"
p2 = "  .....................................\bbbb.txt"
p3 = " ......................................\ccccc.txt"
p4 = " ......................................\dddddd.txt"
p5 = " .....................................\eeee.txt"
p6 = " ....................................\ffffff.txt"

all = exefile & p1 & p2 & p3 & p4 & p5 & p6

retval = shell(all,1)

It doesn't work when parmstring is too long.

Does anybody know if there is a limit with length of parms passed ? Is there a solution to bypass this problem ?


Theres a 120 character limit on command lines. This is after parameter substitution. This is intrinsic in DOS and you can't work around it.


however, in your example, all the data files come from one directory.  will that fact hold in all cases? if so, you can make parm 1 be the common directory, and subsequent parms be files in that directory...

good luck!

Thank you mark2150 and Larry  for your answer.

Indeed, Larry, all files come from one directory and I will follow your advice to bypass the problem.

Best regards,

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.