Solved

Parameter passing while shelling out to DOS

Posted on 1998-08-18
3
163 Views
Last Modified: 2010-04-30
I want to shell out to DOS from my program, using a batch file, and run a utility using one of the variables from my program as a parameter.  I've mastered the shelling out, and writing batch files, how do I pass the variable?
0
Comment
Question by:bigc
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
fmismetti earned 50 total points
ID: 1429580
Did you try:

    Dim Ret As Long

    Ret = WinExec("c:\dosprog\d.bat parm1 parm2", 1)

You need to concatenate the batch filename plus your variable(s) converted to strings.

If Ret is greater than 32, the exec is ok.

The parameter 1 is for SW_SHOWNORMAL Constant (look in the API viewer) and controls how the window is showed. You need also to declare:

Declare Function WinExec Lib "kernel32" Alias "WinExec" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long

Hope that help you
0
 

Author Comment

by:bigc
ID: 1429581
The program shells out to DOS and runs the batch file, but is still passing the variable name as the parameter rather than the contents.  

I put the 'Declare Function WinExec Lib ...." in a module, as it wouldn't work in the main section of the program.  

Any more top tips?

Thanks
0
 
LVL 1

Expert Comment

by:fmismetti
ID: 1429582
Well, which is passed to the shell is a single string. In the sample above, I assume that parm1 and parm2 are string variables. If your variable is an integer you should convert and prepare a single string like:

    Dim parm1int as integer
    Dim parm2int as integer
    Dim appname as string
    Dim CommStr as string

    CommmStr=appname & " " & Format(parm1int,"####0") & " " & Format(parm1int,"####0")

    Pass CommStr to WinExec.


0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 70
Determine Range to Select 5 48
passing a value with stream reader AFTER a ";" 3 66
Automatic Email Reminder 4 37
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question