Results 1 to 17 of 17

Thread: Associate files...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87

    Unhappy

    I asked it already yesterday but it won't work so I ask it again:

    I want to associate my program with a specific file format. When someone clicks the file I would like to have my program opened and the file loaded. So I need to know the filename of the clicked file to load it with my program. Can somebody help me please by sending a clear explanation or an example project??

    Thanx

  2. #2
    Guest
    See This tip

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87
    I tried this code already but this stuf doesn't work in VB6 enterprise. And I register my extension with a .reg file so that isn't the problem. The problem is how can I get the filename of the clicked file with my program?

  4. #4
    Guest
    That's passed through the Command line argument. The command line argument is represented by Command in VB. I.e If you made a Text Editor, you can use the following code to open the file that was clicked on.

    Code:
    Private Sub Form_Load()
    
        Open Command For Input As #1
        Text1.Text = Input(LOF(1), 1)
        Close #1
        
    End Sub

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This one will allow several files to be opened with your app, storing file contents in yourarray
    Code:
       Dim X as integer, File as variant, Yourarray() as string
        For each File In split(command$," ")
           Open File For Input As #1
             Redim Preserve Yourarray(X)
             Yourarray(X)=Input(Lof(1),1)
             X=X+1
           Close #1
        Next File
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87
    When i try this code
    Open command For Input As #1
    Text1.Text = Input(LOF(1), 1)
    Close #1
    I get this error message:

    Run-time error '75'
    Path/file acces error

    What am I doing wrong?

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    When the file association is registered, make sure that the %1 is in quotes:
    Code:
    c:\myprog\myprog.exe "%1"
    Then you can split long filenames up properly.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Guest
    moperke:

    I had that same problem,

    i wanted to see why it wasnt working, so before I had the open code, I popped up a message box that told me what the "Command$" was,
    it turns out there are quotes around the file name
    so I did this

    Code:
    Dim FF As Integer
    Dim FName As String
    
      FF = FreeFile
    
      FName = Replace(Command$, Chr$(34), " ")
      FName = Trim$(FName)
    
      Open FName For Input As FF
        Text1 = Input(LOF(FF), FF)
      Close FF

    also, one more question,
    how do I get the correct icon??
    I can open files in my app, etc etc, but how do I get the icon?
    I tried setting the default icon with the path to my exe and ",1" and I even tried using the ICO File....

    I used the tip megatron posted the link to..

    Thanks,
    Dennis Wrenn

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87
    thanx everyone who helped me, it works!
    ...
    but I have a new problem: when my exe is located in a folder which contain spaces (like c:\Program Files\MyFolder\MyApp.exe) the command gives a DOS path like H:\DATA\MYFILE~1.EXT and I get a File not found error. How can I fix this problem?

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87
    To change the icon you have to edit the 'DefaultIcon' in the registry. It's located in the same dir as 'Shell'.

  11. #11
    Guest
    I know that, I just cant seem to get the correct Icon, I have tried setting the default icon for a real icon, and for the exe's icon.....
    please somebody help...

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    For an icon file, just reference it c:\myicon.ico

    For an exe or dll, use c:\mydll.dll,4 where 4 is replaced by the index of the icon in the file.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  13. #13
    Guest
    I tried that, it doesnt work.

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Where are you putting it?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15
    Guest
    HKEY_CLASSES_ROOT\ViewNFO\DefaultIcon

    this is the path

    C:\PROGRAM FILES\VIEWNFO\viewNFO.exe,1


  16. #16

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87

    Question Another question

    My program opens the files correctly but when I click a second file my program loads also a second time. What I want to do is open the second file with the same program as the first.
    Any suggestions?

  17. #17
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use DDE. That's mainly what it's there for.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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