VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Reading Command Parameters

by Jonathan Jarvis (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Have you ever wanted to click a file and open it? If your program is associated with a specified file type, or you select file(s) and drag them onto the exe icon of your app then this code is for you. It reads the parameters when the form is loaded using by getting the "Command".
This code can get each file dragged or clicked on. If you just use the command statement you will get something like this "c:\george.bmp c:\ben.bmp f:\mydoc.doc". This code seperates each file and uses another sub to open it.

Inputs
If you want to use this code so far you will need a listbox with a name of "List1"
Assumes
This uses some some simple string work and a loop statement.
Code Returns
THis code returns seperated command parameters
Side Effects
None as of yet

Rate Reading Command Parameters

'Code created by Jonathan Jarvis - Jman
'Email: [email protected]
'as of now this will require a listbox with a name of "List1"
Private Sub getfiletoopen(filename As String)
List1.AddItem filename
End Sub
Private Sub Form_Load()
'create variables
Dim howlong, n As Integer, c As String
'give variables values
c = Command
n = 1
For howlong = Len(Command) To 1 Step -1 ' start loop statement
If Mid(c, n, 1) = " " Then 'check to see if It should seperate commands
getfiletoopen Mid(c, 1, n - 1) 'pick out the command from line only Mid(c, 1, n - 1) is the command file
c = Right(c, Len(c) - n) 'change command and get rid of last handled file
n = 0 'reset letter to 0
End If
n = n + 1 'increment to next letter
Next howlong 'go on to next letter
'takes care of last command line or 1st one if only one file is to be opened
If c <> "" Then ' checks to see if there is a 1st or last command
getfiletoopen c ' you can change this to load your file or command. c is the command parameter of the last file
End If
End Sub

Download this snippet    Add to My Saved Code

Reading Command Parameters Comments

No comments have been posted about Reading Command Parameters. Why not be the first to post a comment about Reading Command Parameters.

Post your comment

Subject:
Message:
0/1000 characters