Results 1 to 5 of 5

Thread: How can i open a text file if drag it over my text editor executable.

  1. #1
    fifi
    Guest

    Question How can i open a text file if drag it over my text editor executable.

    Hi !
    I am traing to make a text editor and i can not open a text file into my program if i drag the text file over my program executable (before i am opening the program).

    Please anyone take the time and explain to me how to do it.
    Thank you.

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Use command.

    In the Form's load event, check if Len(Command) > 0

    If it is, it will be the filepath and name of the file you dragged onto the icon, unless someone typed the "myEditor.exe qwerty" or something into the command prompt. Check for this.

    Then you can open the text file from the filepath and name

    r0ach™
    Don't forget to rate the post

  3. #3
    error40501
    Guest

    Funny you should ask that!

    I was just experimenting with this.

    If you start an exe from a command line, like a dos window, you can pass the name of (say) a file to it thus:

    c:> myprog.exe myfile.txt

    The name myfile.txt goes into a string called command, which you don't need to dim, it's there already.

    But to answer your question- I found that as long as you're using this command approach, it works for drag-n-drop as well. It only seems to work for an exe that isn't started yet (which is what you want); if the app is going, I get the 'no entry' sign in explorer and can't drop it in.

    So you would need a line something like:

    FileToOpen = command

  4. #4
    Junior Member
    Join Date
    Oct 2001
    Posts
    21

    let me explain

    Hi fifi,

    This is really not as difficult as you might think...

    When in the DOS-age (the ancient operating system ), programs could be started with a parameter. In QuickBASIC the parameter could be read by the following command:

    sCommand = Command$
    Print sCommand

    When this program was started like this: "C:\>runme wild", the program would return, on screen: "wild"

    In Visual Basic the parameter thing works just the same! When a file is dragged over the application you would like to start, the program is started using the parameter with the name of the file.

    So, to start off... Create a visual basic form. In the Form_Load event, type the following:

    ---
    Dim sCommand as String
    Dim sarrParam() as String

    ' Here we get the parameters.
    sCommand = Command$
    sarrParam = split (sCommand, " ")

    If UBound (sarrParam) = 0 Then MsgBox "No parameter given..." Else MsgBox UBound (sarrParam) & " parameter(s) given..."
    ---

    The first parameter value would be: sarrParam(0), the second: sarrParam(1), ...

    I hope you understand it now!

  5. #5
    fifi
    Guest

    Thanck you all

    Firs of all let me say to you all thanck's a lot, you have showed me that it is a simple thing.
    Second i want to say that i have not found another forum in with the response comes so quickly, and so detailed.

    You are the greatest.

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