Solved

VB GetCommandLineArgs

Posted on 2003-10-30
5
813 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
5 Comments
 
LVL 4

Accepted Solution

by:
brother7 earned 500 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
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…

747 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

9 Experts available now in Live!

Get 1:1 Help Now