none
Help with Program.GetArgument

    Question

  • While waiting for V 1.0 of Small Basic, I'm reviewing all the Proprieties, Operations and Events of the VB language. I'm having problems understanding the Program.GetArgument operation. Could someone explain it to me and give me a simple example to illustrate it.
    Thursday, May 26, 2011 2:14 PM

Answers

  • You could also use Program.GetArgument() to read files. If you used this:

     

    argument = Program.GetArgument(1)

    If argument <> "" Then

     

    Then you could get the filepath of a file, say if you dragged a file onto the icon of the application, it would get the filepath of that file.


    ~~AirWaves!!~~
    Friday, May 27, 2011 7:20 AM
  • This reads arguments entered on the command line.

    This is a test SmallBasic program:

    numArgument = Program.ArgumentCount
    For i = 1 To numArgument
      TextWindow.WriteLine(Program.GetArgument(i))
    EndFor

    Save it somewhere and run it to compile it, I called it arguments.  This creates an executable called arguments.exe.

    Start the command window (Start|Run.. and enter cmd).  Navigate to where the compiled file was stored using cd to change directory.

    Then type the compiled program name with some arguments:

    arguments hello world

    This then starts the SmallBasic program and prints

    hello

    world

     

    Thursday, May 26, 2011 8:09 PM
    Moderator
  • Or if you're going to make a shortcut for it, you can add the arguments in the shortcut adderess
    Check out my website: http://k-dev.webs.com/
    Friday, May 27, 2011 4:57 PM

All replies

  • This reads arguments entered on the command line.

    This is a test SmallBasic program:

    numArgument = Program.ArgumentCount
    For i = 1 To numArgument
      TextWindow.WriteLine(Program.GetArgument(i))
    EndFor

    Save it somewhere and run it to compile it, I called it arguments.  This creates an executable called arguments.exe.

    Start the command window (Start|Run.. and enter cmd).  Navigate to where the compiled file was stored using cd to change directory.

    Then type the compiled program name with some arguments:

    arguments hello world

    This then starts the SmallBasic program and prints

    hello

    world

     

    Thursday, May 26, 2011 8:09 PM
    Moderator
  • Thanks. I can make it work but I still don't comprehend in what circumstances I would use it!!
    Thursday, May 26, 2011 8:51 PM
  • We don't use command line programs much in Windows, but on linux for example they are used all the time - you can make small utility programs similar to bat files that do something using some user input (the arguments), perhaps a program to count the number of words or lines in a textfile using the filename as an argument.

    Thursday, May 26, 2011 9:04 PM
    Moderator
  • Thank you.
    Thursday, May 26, 2011 11:29 PM
  • You could also use Program.GetArgument() to read files. If you used this:

     

    argument = Program.GetArgument(1)

    If argument <> "" Then

     

    Then you could get the filepath of a file, say if you dragged a file onto the icon of the application, it would get the filepath of that file.


    ~~AirWaves!!~~
    Friday, May 27, 2011 7:20 AM
  • Or if you're going to make a shortcut for it, you can add the arguments in the shortcut adderess
    Check out my website: http://k-dev.webs.com/
    Friday, May 27, 2011 4:57 PM