Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you pass command line arguments to compiled VB programs

Status
Not open for further replies.

spacey

Programmer
Oct 15, 1999
10
US
I need to pass a value to an external VB application from a Web page. I would like to use something like &quot;program.exe -q12345&quot; where 12345 is a record number in a database. Can this be done?<br>
<br>
Please help.
 
Assuming you are the developer of said VB app, you have to enable the startup object (form or main sub) to accept this argumant. There is a VB function called 'Command$' that does this very thing.<br>
<br>
The code in your app would look something like this (a form is the startup object in this case)&quot;<br>
<br>
sub Form_Load()<br>
dim sArg as string<br>
dim iQ as integer<br>
dim iSpace as integer<br>
dim sRec as string<br>
dim lRec as long<br>
<br>
'get command line arguments<br>
sArg = Command$()<br>
<br>
if len(sArg) then<br>
'look for '-q'<br>
iQ = instr(lcase$(sArg), &quot;-q&quot;)<br>
<br>
if iQ then<br>
'iQ exists, look for space after iQ<br>
iSpace = instr(iQ+2, sArg, &quot; &quot;)<br>
if iSpace &gt; 0 then<br>
'get characters between iQ and space<br>
sRec = mid$(sArg, iQ+2, iSpace-iQ-2)<br>
else<br>
'get all characters after iQ <br>
sRec = mid$(sArg, iQ+2)<br>
end if<br>
<br>
if isnumeric(sRec) then<br>
lRec = val(sRec)<br>
bResult = GoGetDatabaseRecord(lRec)<br>
else<br>
'non numeric data has been passed in<br>
'cannot retrieve record by number<br>
end if <br>
else<br>
'-q parameter not found...<br>
end if<br>
<br>
else<br>
'no arguments passed in<br>
'do default...<br>
end if <br>
<br>
end sub<br>
<br>
This is a pretty simple implementation. You probably want to check for other argument types in addition to the '-q'. You just have to get creative with a string parser. By the way, the VB6 documentation has an example of this.<br>
<br>
Hope it helps,<br>
-Motts
 
Thanks Motts, now that I know the Command$() command I shouldn't have any trouble.<br>
<br>
Thanks again.<br>
Spacey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top