Solved

VB GetCommandLineArgs

Posted on 2003-10-30
5
821 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 54
How to set the sa password in a vb6 code for sql connection 9 52
How to Add / Edit Windows Menu 4 60
Added a column screws up code 5 57
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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