|
-
Jan 3rd, 2008, 02:15 AM
#1
Thread Starter
Hyperactive Member
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
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Jan 3rd, 2008, 02:30 AM
#2
Hyperactive Member
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!
-
Jan 3rd, 2008, 02:51 AM
#3
Thread Starter
Hyperactive Member
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
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Jan 3rd, 2008, 03:01 AM
#4
Hyperactive Member
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?
-
Jan 3rd, 2008, 07:48 AM
#5
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.
-
Jan 3rd, 2008, 09:51 AM
#6
Frenzied Member
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.
-
Jan 31st, 2008, 09:24 AM
#7
Thread Starter
Hyperactive Member
Re: command line arguments, i think
 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
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Jan 31st, 2008, 10:19 AM
#8
Re: command line arguments, i think
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|