Passing parameters to a VB 6.0 program

Posted on 2005-03-17
Medium Priority
Last Modified: 2010-04-23
Is it possible to pass a parameter to a VB 6.0 program.  For instance i want my program to react when a file name has been passed to it.  I know you can change the start up form to Sub Main() but it does not allow you to place a variable inside E.X. Sub Main(Dim CFileName as String).  I know you can do this in C++ when you creat a document program but i cant find a way to do it in VB.
Question by:TerencDwyer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13569755
You've placed this question in the VB.net area.

Do you want this for VB6 or VB.Net?
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 13569780
In VB6 you can use the Command() function to get the command line parameters.  Then you can split with the space character to break it down into parts as in this example:

Private userName As String
Private password As String
Private dataPath As String

Private Sub Form_Load()
    Dim parameter As Variant
    parameter = Split(Command())
    If UBound(parameter) = 2 Then
        userName = parameter(0)
        password = parameter(1)
        dataPath = parameter(2)
        Dim msg As String
        msg = "userName = " & userName & vbCrLf & _
            "password = " & password & vbCrLf & _
            "dataPath = " & dataPath
        MsgBox msg
        MsgBox "Invalid Number of Parameters"
    End If
End Sub

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

777 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