Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

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
0
cavagnaro
Asked:
cavagnaro
4 Solutions
 
Z03niECommented:
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 SasidharanCommented:
'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
 
Bob LambersonSoftware 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
 
Robberbaron (robr)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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now