Solved

Parameter passing while shelling out to DOS

Posted on 1998-08-18
3
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

734 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