Click here to Skip to main content
14,975,411 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am working on a project that communicates with robots, I need to debug the code with the robots offline.

I want to set a variable based on command line parameters.

How can I set a variable in Main that is visable throughout the project?

Thanks in advance for your help.
OriginalGriff 14-Jun-12 15:40pm
Which version of VB?

1 solution

If VB (not .NET), see this example:
Function Main(ByVal CmdArgs() As String) As Integer
   Dim ArgNum As Integer   ' Index of individual command-line argument.
   If CmdArgs.Length > 0 Then   ' See if there are any arguments.
      For ArgNum = 0 To UBound(CmdArgs)
         ' Examine CmdArgs(ArgNum) for settings you need to handle.
      Next ArgNum
   End If
   MsgBox("Hello World!")   ' Display message on computer screen.
   Return 0   ' Zero usually means successful completion.
End Function

In VB.NET, start here: How to: Access Command-Line Arguments (Visual Basic) [^][^]
Other useful links:[^][^][^]
How to Pass Command Line Arguments to MSI Installer Custom Actions[^]
jonsey29847 15-Jun-12 11:47am
I did not explain myself enough, there are several 'projects' across the application. And what I am trying to do is provide a global solution. My concept is to provide an argument, use that argument to set a boolean to true, then use that boolean in each 'project' for the same function.

What I think you are telling me is that I have to parse the command line in each project, a bit more work. I must admit I was hoping for a more glamorous solution when in the IDE.

A second issue is if the application is executed by windows, I am assuming the command line args will not be present.
Maciej Los 21-Jun-12 17:33pm
Add a module to your project. Declare a variant, like: Public myVar as Boolean = True. If you have many 'projects', you'll need to use Enum, like this:
Enum AppContext
.Project1 = 0
.Project2 = 1
.Project3 = 2
End Enum

Then: CurrentContext = AppContext.Project1 -> Example
Sandeep Mewara 21-Jun-12 16:52pm
My 5!
Maciej Los 21-Jun-12 17:20pm
Thank you, Sandeep ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900