Opening a file argument?

Discussion in 'Questions (Windows Mobile)' started by Hennell, Mar 10, 2008.

  1. Hennell

    Hennell Member Licensed User

    How do you get a file name argument when a file is chosen from within a file manager?

    I can make it so I tap on a file and my program launches, but I want it to load the file I tapped on as well, which I can't work out how to code. I figure its probably an argument option or something, but I can't work it out. What do I have to do?
     
  2. agraham

    agraham Expert Licensed User

    Look in Help->Main Help->Basics->Command Line Arguments, it tells you there.
     
  3. Hennell

    Hennell Member Licensed User

    Afraid I don't really understand the help on it, I assume the program will be launched with the file name as an argument but I can't see how I capture that to use. Might fiddle with the code shown in help, but I could do with some more pointers...

    (Also I apologise, but I seem to have posted this in 'Code Samples and Tips', rather then the more suitable 'questions/help needed' forum. Can someone move it? I've no idea why I put it here.... *feels silly*)
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Do you mean that you want to associate a specific file extension with your application?
     
  5. agraham

    agraham Expert Licensed User

    Code:
    ...
    NumberOfArguments = ArrayLen(args())
    FirstArgument = args(
    0)
    SecondArgument = args(
    1)
    ...
     
  6. Hennell

    Hennell Member Licensed User

    Ah, thanks agraham, the help file, your last comment and some trial and error seem to have got it all working now. Suddenly it all seems quite obvious. :sign0161:

    my code for anyone else with the problem is:

    Code:
    (In app start)
    If ArrayLen(Args()) = 1 Then 'Will catch if a single argument is given. (Like a file name)
       file = args(0)
       
    If SubString(file,StrLength(file) - 33) <> "jgf" Then 'Checks the file extension to see if its the right type. 
          Msgbox(File & " is not a valid file","Error")
          
    Return
       
    End If
       opendialog1.File = 
    file
       LoadFile
    Which seems to work fine.

    EDIT: First version only worked when given an argument to check. :signOops:. New code checks if the argument is there...
     
    Last edited: Mar 11, 2008
Loading...