Send to VB app parameters from command line

Hi,
I need to create a VB app which receives external parameters from command line and do something. I'll like to know if somebody has some basic code to do it.

For example:

c:\>vbapp.exe hello 2

and in VB for example some like:

for i=0 to param2
  alert param1
next

I hope my idea is clear.

Basically i need this to integrate one existing app in powerbuilder to a new one i must create so powerbuilder sends data to vb app and do something

Thanks
LVL 2
cavagnaroAsked:
Who is Participating?
 
Bob LambersonConnect With a Mentor Software EngineerCommented:
> c:\>vbapp.exe hello 2

> and in VB for example some like:

> for i=0 to param2
>   alert param1
Option Explicit
'compile this project into an exe and run with the parameters.....
'c:\>vbapp.exe hello, 2

add this code to your form.........

Private Sub Form_Load()
   Dim x As Variant
   Dim cmdArray As Variant
   x = Command()              'x will hold the command line variables
   cmdArray = Split(x, ",")
   'now cmdArray(0) will contain the value "hello"
   ' and cmdArray(1) will contain the value 2
   ' do someting with the passed in values.

End Sub

Bob
0
 
Z03niEConnect With a Mentor Commented:
Maybe you can use this solution.
In the main form load, or sub main or whatever first sub that you call first put this code :

  Dim strargs() As String
  dim param1 as string
  dim param2 as integer
  If Command() = "" Then Exit Sub    'command() holds all of the arguments given to the executable
    strargs() = Split(Command(), " ")  
    param1 = strargs(0)
    param2 = cint(strargs(1))

  for i=0 to param2
    alert param1
  next


Hope that help.

 
0
 
Shiju SasidharanConnect With a Mentor Assoc Project ManagerCommented:
'Make Exe of ur Project and try like this in command prompt
'   C:\Project1.exe arg1 arg2 arg3
'=============================================
Private Sub Form_Load()
 Dim args() As String
 Dim i As Integer
    If Command = "" Then
       MsgBox "Arguments Empty"
       Exit Sub
    End If
    args = Split(Command, " ")
    For i = 0 To UBound(args)
      MsgBox args(i)
    Next
    Erase args
End Sub
'=============================================

;-)
Shiju
0
 
Robberbaron (robr)Connect With a Mentor Commented:
If you want it to run properly without showing a form when called from another program,
set the Project Property to 'Run Unattended' and dont add any forms. (it wont let you i think...)

Create a module with Sub Main in it, then use any of the first 2 code samples above to get paramaters. (sample 3 splits on a comma, which is not usual on a command line. )

Note the code above requires VB6 for the Split command.
There are lots of routines around to do the same in VB5. let me know if u need one.
0
 
cavagnaroAuthor Commented:
Last 3 answers are fully code operative and very helpful. Thanks
0
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.