Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB GetCommandLineArgs

Posted on 2003-10-30
5
Medium Priority
?
866 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

877 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