|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Reading command line arguments in VB
hi all,
i wanted to know how do we read command line arguments in VB program. regards, rashmi |
|
#2
|
||||
|
||||
|
The arguments get put into a variable called $Command, just check if something is in there:
If Command <> "" then msgbox "Arguments: " & Command else msgbox "No arguments passed" end if |
|
#3
|
|||
|
|||
|
I'm working on a project where I have to accept arguments in my VB code as well. The problem is this: I need the argument, which is a user name, to be used in a file path. For example:
Public Sub Form_Load() Call Args Dim strFileName1 As String strFileName1 = "C:\iFtpSvc\Hms-ftppro\users\" & CmdArgs & "\" & CmdArgs & ".txt" Open strFileName1 For Input As 1 Call PrintReport End Sub Public Sub Args() Dim CmdArgs As String CmdArgs = Command$ 'MsgBox CmdArgs End Sub When I have the code put the argument in the message box, it works correctly. However, when I try to insert the user name argument in the file path, it does not work. Can anyone help?? If this is not clear enough, please let me know so I can clarify. Thanks! |
|
#4
|
||||
|
||||
|
your not returning the CmdArgs in the sub
before ending the sub put this Args = CmdArgs |
|
#5
|
|||
|
|||
|
reading command line args
Thanks for your reply, Anacrusis, but it's still not working. I added Args = CmdArgs to the Sub and then changed the Sub to a Function. I get a file not found error because the app can't read the path. Any other suggestions??
Thanks! |
|
#6
|
|||
|
|||
|
Try This
Going with what Anacrusis told you to do. Also ensure that the returned string value is what is being used and not the CmdArgs variable which is only defined locally in the Args function. May also want to do a trim to ensure no extra whitespace that may throw off the search for path.
Public Sub Form_Load() Dim strFileName1 As String strFileName1 = "C:\iFtpSvc\Hms-ftppro\users\" & Args.Trim() & ".txt" Open strFileName1 For Input As 1 Call PrintReport End Sub Noticed you had CmdArgs in two places for the file name, so you may have to update your Args function to return an array of strings. Do manipulation of the string values you want in Args function and return to String array in Form_Load(). Then you can say: strFileName1 = "C:\iFtpSvc\Hms-ftppro\users\" & strArgs(1) & "\" & strArgs(2) & ".txt" Or you can just manipulate the path in args to be the full path after users, so only you need to put is: strFileName1 = "C:\iFtpSvc\Hms-ftppro\users\" & Args Hope that makes sense. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Reading command line arguments in VB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|