Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB GetCommandLineArgs

Posted on 2003-10-30
5
Medium Priority
?
856 Views
Last Modified: 2008-03-10
Hi Experts,

For some reason I cannot get thing working. I have tried all
possible code samples from Microsoft site and Experts-Exchange but
all of them give me "Object Reuired" error "424" on the line where
I have


args = GetCommandLineArgs()

args defined as Dim args() As String

Can anyone tell me what's wrong. I had to check if I missed some library but
even in my Object Library viewer I cannot see these GetCommandLineArgs.

Please help.

0
Comment
Question by:fpoyavo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Accepted Solution

by:
brother7 earned 2000 total points
ID: 9654329
Have you tried this?

--- Code Start ---

Function GetCommandLine(Optional MaxArgs)
   'Declare variables.
   Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs
   'See if MaxArgs was provided.
   If IsMissing(MaxArgs) Then MaxArgs = 10
   'Make array of the correct size.
   ReDim ArgArray(MaxArgs)
   NumArgs = 0: InArg = False
   'Get command line arguments.
   CmdLine = Command()
   CmdLnLen = Len(CmdLine)
   'Go thru command line one character
   'at a time.
   For I = 1 To CmdLnLen
      C = Mid(CmdLine, I, 1)
      'Test for space or tab.
      If (C <> " " And C <> vbTab) Then
         'Neither space nor tab.
         'Test if already in argument.
         If Not InArg Then
         'New argument begins.
         'Test for too many arguments.
            If NumArgs = MaxArgs Then Exit For
            NumArgs = NumArgs + 1
            InArg = True
         End If
         'Concatenate character to current argument.
         ArgArray(NumArgs) = ArgArray(NumArgs) & C
      Else
         'Found a space or tab.
         'Set InArg flag to False.
         InArg = False
      End If
   Next I
   'Resize array just enough to hold arguments.
   ReDim Preserve ArgArray(NumArgs)
   'Return Array in Function name.
   GetCommandLine = ArgArray()
End Function

--- Code End ---
0
 
LVL 4

Expert Comment

by:brother7
ID: 9654343
In addition, isn't GetCommandLineArgs a VB.NET method, not a VB6 one?
0
 
LVL 4

Expert Comment

by:steveo225
ID: 9654474
Dim VarT As String
Dim VarF As String
Dim VarC As String
Dim MyArray() As String

MyArray() = Split(Command(), " ")
For Each Item In MyArray()
       If InStr(1, Item, "-t=") Then VarT = Replace(Item, "-t=", "")
       If InStr(1, Item, "-f=") Then VarF = Replace(Item, "-f=", "")
       If InStr(1, Item, "-c=") Then VarC = Replace(Item, "-c=", "")
Next
If VarT <> "" Then MsgBox VarT
If VarF <> "" Then MsgBox VarF
If VarC <> "" Then MsgBox VarC

Replacing VarT, VarF and VarC with your specific variables of course
Just put this code at the top of your form load routine
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9654916
Try this

'This is .net code
Dim args As [String]() = Environment.GetCommandLineArgs()
Console.WriteLine("GetCommandLineArgs: {0}", [String].Join(", ", arguments))

Thanks,
~ fantasy ~
0
 
LVL 2

Expert Comment

by:diarmaid
ID: 9657361
As brother7 states above you use the Command() function to retrieve command line args.
Using brother7's code above, In Sub Main or Form_Load use following to get array of command line args:
Dim ar
ar = GetCommandLine

To check using the VB IDE you need to set the command line properties in the make tab of the project properties dialog
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.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

722 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