Solved

command line argument

Posted on 2002-04-18
9
223 Views
Last Modified: 2010-05-02
how can i use command line arguments on my VB application?

for instance:
If I run this command from the command line, it should display the sum of the arguments...

c:\MyApp.exe /x=1 /y=2

0
Comment
Question by:killer5
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 10 total points
ID: 6949872
Your initial Sub Main or Form_Load should do something like this:

Private Sub Form_Load()
  Dim strCommand As String
  Dim aryParms() As String
  Dim aryValues() As String
  Dim intParm As Integer
  strCommand = Command()
  aryParms = Split(strCommand," ")
  For intParm = LBound(aryParms) To UBound(aryParms)
    aryValues = Split(Replace(aryParms(intParm),"/",""),"=")
    Select Case aryValues(0)
    Case "x"
      x = aryValues(1)
    Case "y"
      y = aryValues(1)
    End Select
  Next
End Sub
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6949875
Oh, forgot the sum bit:

Msgbox x + y

After the for .. next loop.
0
 

Expert Comment

by:sierrahalflife
ID: 6950250
the important bit of that is the 'Command' variable.
If I called myapp.exe /a /b 1, Command would be "/a /b 1"
you should consider splitting at the slash, rather than the space if your app uses an argument like /time 5, as opposed to /time=5, otherwise it would take /time and 5 as separate arguments.

--SHL
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 43

Expert Comment

by:TimCottee
ID: 7007983
Why a 'C' grade?
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7008530
killer5

COuld you please explain why expert TimCotte only received a "C" grade for his answer? Please provide feedback if you are not happy with an answer and our experts will try to clarify their comments.


Here are the guidelines for grading:

A: The Expert(s) either provided you with a thorough answer or they provided you with a link to information that thoroughly answered your question. An "A" can also be given to any answer that you found informative or enlightening beyond the direct question that you asked.

B: The Expert(s) provided an acceptable solution, or a link to an acceptable solution, that you were able to use, although you may have needed a bit more information to complete the task.

C: Because Experts' reliability are often judged by their grading records, many Experts would like the opportunity to clarify if you have questions about their solutions. If you have given the Expert(s) ample time to respond to your clarification posts and you have responded to each of their posts providing requested information; or if the answers, after clarification, lack finality or do not completely address the issue presented, then a "C" grade is an option. You also have the option here of just asking Community Support to delete the question.


** Mindphaser - Community Support Moderator **
0
 

Expert Comment

by:sierrahalflife
ID: 7008674
Because he's stingy?
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7016056
Grade changed for TimCottee.

** Mindphaser - Community Support Moderator **
0
 

Expert Comment

by:ComTech
ID: 7016323
Hello killer5, keep grading people like this, and you will lose support for most of the Experts, as they do look at how Customers you grade, before answering or just joining in.


I am behind Minphasers decision on the grade change.  Should you have a problem with the change,

I can be contacted at comtech@experts-exchange.com , if so, then please reference this question number 20290788

Regards,
ComTech
CS Admin @ EE
0
 
LVL 1

Author Comment

by:killer5
ID: 7094567
oh... sorry guys. i didn't know why i put a grade C on this. maybe i made a mistake. and i don't know that it was a big deal.. sorry :)
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

778 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