A useful facility within VB is the ability to pass arguments into a
compiled executable as it launches. These arguments are defined in the
command line immediately after the executable. Obviously double clicking
the executable provides no facility to pass arguments, however calling
your application from the Run option on the Start menu or from within
another VB executable allows arguments to be passed as follows: myApp.exe -res:800x600 /ADMINACCESS
These arguments have no effect upon the executable, unless they are interrogated
using the Command() function, then the applications appearance and
functionality can be conditionally determined. Within the initialization
code for your application, perhaps in the Sub_Main or Form_Load
procedures, these arguments can be used to set attributes of your
application. Using Form_Load, with the above command line arguments as an
example, the code below could be employed to conditionally initialize your
executable: Option Explicit
Public gstrAccessLevel as String
Private Sub Form_Load()
Dim strCommandLine as String
'set string to command line arguments
strCommandLine = UCase(Command())
'determine screen res & form size
If Instr(strCommandLine, "-res:1024x768") > 0 Then
Me.Width = 12500
Me.Height = 10000
ElseIf Instr(strCommandLine, "-res:800x600") > 0 Then
Me.Width = 10000
Me.Height = 8000
Else 'assume 640x480 res
Me.Width = 8000
Me.Height = 6400
End If
'determine access level
If Instr(strCommandLine, "/ADMINACCESS") > 0 Then
gstrAccessLevel = "Administrator"
Else
gstrAccessLevel = "StandardUser"
End If
Sub End
|