Passing Args

Discussion in 'Questions (Windows Mobile)' started by Cableguy, Jul 6, 2007.

  1. Cableguy

    Cableguy Expert Licensed User

    Hi, anyone tryed to pass args from one basic4ppc app to another....I don't understand exactly how to catch the args....
  2. stbi

    stbi Member Licensed User

    You catch the args with the array args. args(0) is the first parameter, args(1) the second etc, and arraylen(args) returns the number or arguments.
    It's documented with a sample in the online help, Basics - Command Line Arguments.
  3. agraham

    agraham Expert Licensed User

    Unzip - run Sender - watch what happens - Examine code

    Its crude and needs length checking etc.
  4. dzt

    dzt Active Member Licensed User

    I didn't tested it but it should work like the following.

    At caller App
    shell("prog.exe", "arg1 arg2 arg3")

    At called app
    msgbox(arg(0)) 'shows "arg1"
  5. Cableguy

    Cableguy Expert Licensed User

    Hi guys...

    After my litle fiasco when sharing the backup utility....I've came back to the IDE...

    Strangely enought the code works on the IDE when simulated args in the command line are passes usingt the integrated command line args simulater...
    But it doesn't work when I try to pass from another project...

    The Shell command should be something like "Shell("Backup.exe","thefilename")

    Here are the two files:

    Attached Files:

    Last edited: Jul 7, 2007
  6. Erel

    Erel Administrator Staff Member Licensed User

    Are you passing the full path?
    If there are spaces in the path you should add chr(34) (quotes) before and after it.
    Attached is a small desktop executable that shows the arguments it received.
    This is the code:
    Sub Globals

    End Sub

    Sub App_Start
    for i = 0 to ArrayLen(args())-1
    msgbox("Arg(" & i & "): " & args(i))
    End Sub
  7. Cableguy

    Cableguy Expert Licensed User

    No, im not passing the full path, just the filename without the extension...

    I believe to have it sorted out now....I will keep this updated....

    BTW: could you please delete the thread on "share your creations"?, theres no point on keeping it untill Im 200% sure this works....
  8. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Is this the thread that backed up B4PPC source code???

    I could have swore that I saw a thread started by you but am now unable to find it.
    My intention was to have a look at it when I got chance and then maybe modify it so that it only save the last 5 backup's so as to save some disk space.

  9. Cableguy

    Cableguy Expert Licensed User

    You saw right...
    But the code I posted strangely enought wasn't working as it should when passing the args from another app...I have it sorted out and working but I'm embarassed to the point of not being to crazy of reposting....Still....
  10. Cableguy

    Cableguy Expert Licensed User

    Now that I've sorted out what was wrong with my first attemp at passing args, another question pops out:

    How can we deternine if any arg was passed?

    I need my app to determine the course of action by detecting if any arg was passed or not...If it was passed then execute the main funcion if no args were passed then execute a few secondary ones...

    Being Args an array I tryed the Args.count...wasn't recognized by the designer...
    Is there any incomvinient in declaring the Args array in the globals?
  11. agraham

    agraham Expert Licensed User

    Try ArrayLen(args())
  12. Cableguy

    Cableguy Expert Licensed User

    Second Time You Help me today with 100% success...I was using count as Args is an ArrayList, it just didn't cross my mind to see it as a normal array!!!!lol
  13. horatio

    horatio Member

    still confused

    i tried the 'sender.exe,receiver.exe' programs and they work fine on the desktop. how do you get them to work on the ppc though. i've looked at other threads relating to args and the help file but i'm not getting anywhere. thanks for your efforts
  14. Erel

    Erel Administrator Staff Member Licensed User

    You should just copy them to the device and run Sender.exe.
  15. horatio

    horatio Member

    This is what i get:-

    An unexpected error has occurred in Receiver.exe.
    Select Quit and then restart this program, or select Details for more information.

    Could not load type System.Windows.Forms.Form from assembly System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=B77A5C561934E089.

    The same error message regardless of which program i run. I run everything from my documents in the device root folder.
  16. Erel

    Erel Administrator Staff Member Licensed User

    Apparently these programs were compiled as desktop executables.
    These files should work.
  17. agraham

    agraham Expert Licensed User

    Oops! Sorry, quick and dirty demo without thinking of the consequences :sign0013:
  18. horatio

    horatio Member

    no joy

    ok, no problem, what am I doing wrong now? When I run 'sender.exe', I get nothing happening, when I run 'receiver.exe', I get 'indexoutofrangeexception' error message. Presumably this is because 'receiver.exe' wasn't meant to be run as a stand alone app but rather as an executable linked to 'sender.exe'. Would it be possible to see the source code for these exes or was it the same as before just compiled for device not desktop?
  19. agraham

    agraham Expert Licensed User

    I got the same results as you. The attached stuff works on the device. The problem was the path to Receiver.exe which seems to work differently on the desktop to the device. Just specifying the filename on the desktop defaults the path to the application directory and works. On the device it seems to need AppPath added to the filename together with a backslash in order to work.:confused:

    EDIT : I forgot to save the amended Sender.sbp before making the zip file. I've attached it separately, discard the one in the zip. Sorry!

    Attached Files:

    Last edited: Nov 4, 2007
  20. horatio

    horatio Member


    thanks for your patience, i've got it now.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice