Results 1 to 8 of 8

Thread: command line arguments, i think

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    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.

  2. #2
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    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:
    1. Sub Main
    2.     Dim cCommands As String
    3.     cCommands = Command()
    4. End Sub
    If you are using a form:
    VB Code:
    1. Private Sub Form1_Load()
    2.     Dim cCommands As String
    3.     cCommands = Command()
    4. 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!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    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.

  4. #4
    Hyperactive Member BillGeek's Avatar
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    440

    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:
    1. Private Sub Form1_Load()
    2.     Dim cCommands As String
    3.     Dim cSwitchFile As String
    4.  
    5.     cCommands = Command()
    6.     'We first check if the correct switch is given
    7.     If Left(cCommands, 2) = "/a" Then
    8.         'Now we get whatever is after the switch
    9.         cSwitchFile = Right(cCommands, Len(cCommands) - 2)
    10.     End If
    11. End Sub
    I hope this is a bit clearer?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  6. #6
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    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
    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.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width