Solved

command line argument

Posted on 2002-04-18
9
220 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
 
LVL 43

Expert Comment

by:TimCottee
ID: 7007983
Why a 'C' grade?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now