command line arguments, i think
How do i make an .exe like this http://www.nirsoft.net/utils/nircmd.html
I'd like to make an .exe with the code i use alot so i dont have to keep writing it out. So then i could use something like this in my programs
shell C:\codes.exe deletefile "c:\test.txt"
I think theyre called command line arguments, but i dont know how to put them in my code, ive looked on google and it says something like using Command() and using modules not forms but dosent give any instructions.
All help appreciated and thnaks in advance
chris1990
Re: command line arguments, i think
It doesn't matter whether you use a module (Sub Main) or a form when the application is started, as long as you get the command line arguments.
If you are using a Sub Main:
VB Code:
Sub Main
Dim cCommands As String
cCommands = Command()
End Sub
If you are using a form:
VB Code:
Private Sub Form1_Load()
Dim cCommands As String
cCommands = Command()
End Sub
The "cCommands" variable will now hold anything after the EXE name. So if you invoke your EXE like such:
test.exe /a /c:Test me.txt
Then cCommands will contain: "/a /c:Test me.txt"
You will need to process these using string functions, or whatever the case might be.
Hope it helps!
Re: command line arguments, i think
thanks, would this example work then:
Code:
Private Sub Form1_Load()
Dim cCommands As String
cCommands = Command()
if /a /"" then
call delete ""
end if
End Sub
Re: command line arguments, i think
I'm not quite sure what your code does. What are the switches that you are looking for?
Are you expecting to run your app using the following syntax:
test.exe /a filename.ext
If so, you'll need to "break up" the command line arguments like follows:
VB Code:
Private Sub Form1_Load()
Dim cCommands As String
Dim cSwitchFile As String
cCommands = Command()
'We first check if the correct switch is given
If Left(cCommands, 2) = "/a" Then
'Now we get whatever is after the switch
cSwitchFile = Right(cCommands, Len(cCommands) - 2)
End If
End Sub
I hope this is a bit clearer?
Re: command line arguments, i think
Instead of an Exe, if you have reusable code, create a class module and compile it into a .DLL that all of your projects can reference.
Re: command line arguments, i think
This one has me thinking. Can anyone point me to a page or website that will explain about programs that use the command line. Where I can learn how to do all the basic sort of things like displaying text, getting input, etc. Thanks.
Re: command line arguments, i think
Quote:
Originally Posted by Hack
Instead of an Exe, if you have reusable code, create a class module and compile it into a .DLL that all of your projects can reference.
Sorry its been a while, been a bit busy with college work.
This was what i was going to do, but i dont understand how to use or create dlls. If you know of a good guide/faq could you please post the link. The ones that i come across on google are to complicated or not enough detail to fully understand it.
Thanks in advance.
Chris1990
Re: command line arguments, i think
Quote:
Originally Posted by chris1990
The ones that i come across on google are to complicated
Well, they are probably as straightforward as it gets.
Another option, although not as elegant, is to put all of the code into a standard .bas module, and simply include that in all of your projects.