• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

How to program for command line switches

I saw emoreau's class example but didn't know how to use it.

Thanks,


Danny
0
jazz4sale
Asked:
jazz4sale
2 Solutions
 
Éric MoreauSenior .Net ConsultantCommented:
which class? I can surely help if it is from me?
0
 
SweatCommented:
jazz4sale,

If you are talking about picking up switches from the command line to your program:

   myprogram.exe /s /p /l

then you would do something like the following in your Sub Main() section.

Sub Main()
   Dim sArray() As String, sCmdLine As String

   sCmdLine = Command()
   If sCmdLine <> "" Then
      sArray = Split(sCmdLine, " ")
      ' Your sArray elements would look like this:
      ' sArray(0) "/s"
      ' sArray(1) "/p"
      ' sArray(2) "/l"
      ' From there you'd set boolean or values to do whatever is needed based on the command line switches.

   End If

End Sub

If you aren't talking about picking up command line switches for your program, then please ignore this.

Sweat

0
 
Shaka913Commented:
Here is how I do it in VB, in the Form OnLoad event

Private Sub Form_Load()
    Dim zI As Integer
    Dim zArgs() As String
     Dim i As Integer
         
    zArgs = Split(Command$, " ")
   For i = LBound(zArgs) To UBound(zArgs)
      Select Case Left(LCase(zArgs(i)), 2)
      Case "-f"
        mFileName = Mid$(zArgs(i), 3)
      Case "-n"
        mFullFilename = Mid(zArgs(i), 3)
      Case "-c"
        mConnectCatalog = Mid$(zArgs(i), 3)
      Case "-d"
        mConnectDataSource = Mid$(zArgs(i), 3)
      Case "-i"
        mFileID = CLng(Mid$(zArgs(i), 3))
      Case Else
         MsgBox "Invalid argument: " & zArgs(i)
      End Select
     
   Next i

...

beware that this assumes that the switches are case INsensitive.

Hope this helps.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Shaka913Commented:
How is this going? are you going to pick an answer?
0
 
CleanupPingCommented:
jazz4sale:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: Sweat and Shaka913

DanRollins -- EE database cleanup volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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