0% found this document useful (0 votes)
10 views

Vba Programme

This document discusses how to execute Visual Basic programs with command line arguments. It explains that command line arguments allow you to modify a program's behavior at runtime by overriding hardcoded values. As an example, it discusses how command line arguments could be used to specify an alternative file path if the usual hardcoded path is invalid, preventing the program from crashing in that situation. It then provides sample code to open, read from, display, and close a text file as part of a command button click event procedure to illustrate the concept.

Uploaded by

ballapanda
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Vba Programme

This document discusses how to execute Visual Basic programs with command line arguments. It explains that command line arguments allow you to modify a program's behavior at runtime by overriding hardcoded values. As an example, it discusses how command line arguments could be used to specify an alternative file path if the usual hardcoded path is invalid, preventing the program from crashing in that situation. It then provides sample code to open, read from, display, and close a text file as part of a command button click event procedure to illustrate the concept.

Uploaded by

ballapanda
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Executing a VB Program with

Command Line Arguments


I frequently receive queries from readers asking if Visual Basic supports Command Line
Arguments. The answer is 'Yes', and in this article, I'll show you how to use them.

For those of you not familiar with the concept, programming languages, such as C and C++,
allow you to execute a compiled program with one or more Command Line Arguments,
which are then used to modify the behavior of the program at run time.

For instance, suppose you write a program to read a text file and process the records in that
file. Suppose 99 times out of 100 that file is located in a specific directory on your Local
Area Network, and so you 'hard code' the file path into your program code. However, that 1
time out of 100 that the file is not where your program expects it to be, the program
unceremoniously bombs. This would be a perfect use for a Command Line Argument, which,
if supplied to the program, can override the 'hard coded' file path. Let me illustrate by first
writing the code to open a file, read the records, display them on the form, and then close
the file. Let's place that code in the Click Event Procedure of a Command Button…

Private Sub Command1_Click()

Dim strValue As String

Open "c:\vbfiles\august2000\test.txt" For Input As #1

Do While Not EOF(1)

Input #1, strValue

Form1.Print strValue

Loop

Close #1

End Sub

You might also like