Results 1 to 5 of 5

Thread: double clicking on a file to launch your program

  1. #1
    Guest
    I want to double click on a file(lets say a *.txt file) and get it to launch my program(lets say a text editor that has a rich text box to load a file into) and have it load the file right into the rich text box with out the user doing anything other than double clicking the original file?
    thanks yall

  2. #2
    Lively Member
    Join Date
    May 1999
    Location
    India
    Posts
    97
    Why don't you write your app' so that it takes the file name as a commandline arguement.
    then simply associate the file type u want with your application, using the standard windows method?

    Or am i missing something???

    Cheers
    [email protected]
    " Programming today is a race between software-engineers striving to build bigger and
    better idiot-proof programs and the universe trying to produce bigger and better idiots.
    So far the universe is winning".
    :-)

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This function will return all command parameters in a variant that contains an array:

    Function GetCommandLine(Optional MaxArgs)
    'Declare variables.
    Dim C, CmdLine, CmdLnLen, InArg, i, NumArgs
    'See if MaxArgs was provided.
    If IsMissing(MaxArgs) Then MaxArgs = 10
    'Make array of the correct size.
    ReDim argarray(MaxArgs)
    NumArgs = 0: InArg = False
    'Get command line arguments.
    CmdLine = Command()
    CmdLnLen = Len(CmdLine)
    'Go thru command line one character
    'at a time.
    For i = 1 To CmdLnLen
    C = Mid(CmdLine, i, 1)
    'Test for space or tab.
    If (C <> " " And C <> vbTab) Then
    'Neither space nor tab.
    'Test if already in argument.
    If Not InArg Then
    'New argument begins.
    'Test for too many arguments.
    If NumArgs = MaxArgs Then Exit For
    NumArgs = NumArgs + 1
    InArg = True
    End If
    'Concatenate character to current argument.
    argarray(NumArgs) = argarray(NumArgs) & C
    Else
    'Found a space or tab.
    'Set InArg flag to False.
    InArg = False
    End If
    Next i
    'Resize array just enough to hold arguments.
    ReDim Preserve argarray(NumArgs)
    'Return Array in Function name.
    GetCommandLine = argarray()
    End Function

  4. #4
    Guest
    "Why don't you write your app' so that it takes the file name as a commandline arguement."

    that exactly what i would like to do, but im not sure how to do it and what i need to do.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Copy the function in my last post and put this in your form_load event:

    For Each n In GetCommandLine
    If Not IsEmpty(n) Then Loadfile n: Exit For
    Next n

    And if you're making an MDI app, remove the Exit for. Rename Loadfile method, for whatever your method is to load the file.

    Hope you get things work now!

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