Click here to Skip to main content
15,886,518 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.
Posted
Comments
OriginalGriff 14-Jun-12 15:40pm    
Which version of VB?

1 solution

If VB (not .NET), see this example:
VB
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) [^]
http://msdn.microsoft.com/en-us/library/3cf7t4xt%28v=vs.71%29.aspx[^]
Other useful links:
http://www.vbdotnetforums.com/console-application/5177-how-parse-command-line-parameters-visual-basic-net.html[^]
http://en.allexperts.com/q/Visual-Basic-1048/VB6-main-arguments.htm[^]
http://65.39.148.52/Articles/16096/VB-6-0-to-VB-NET-Migration-Command-Line-Arguments[^]
How to Pass Command Line Arguments to MSI Installer Custom Actions[^]
 
Share this answer
 
Comments
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