Using Command Line Arguments in Small Basic

GordonH 26 Reputation points
2021-12-24T04:24:19.843+00:00

Hi folks, I am trying to pass a single argument (file name with full directory) into a small basic program from the command line (using a batch file), and do not seem to be having any success.
Using Program.GetArgument(1) to obtain the argument passed, always returns a value of null.
Maybe I am not setting the batch file up correctly.
Can anyone give me an example of the syntax to use ?
E.g. C:\SmallBasic\FileProg.exe E:\Dir1\Dir2\TestFile.txt

Developer technologies Small BASIC
0 comments No comments
{count} votes

Accepted answer
  1. WhTurner 236 Reputation points
    2021-12-24T15:10:25.17+00:00

    I made the following testprogram (called test.sb):
    arg1=Program.GetArgument(1)
    arg2=Program.GetArgument(2)
    TextWindow.WriteLine(arg1+" "+arg2)

    I ran the program, which makes an executable test.exe and when I ran the command "test one two" in the cmd window
    in the directory where text.exe is located. I get a textwindow with the output "one two"

    Try this procedure first and when it works try to get the batch file working.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. JR 126 Reputation points
    2021-12-29T00:51:58.543+00:00

    Gordon-H 7176,

    I created a batch file Mybatch.bat. All that is in it is:

    myprogram c:\temp\test.txt
    exit /B

    It is just the name of my small basic program (myprogram) and the argument that I want to pass (c:\temp\test.txt).

    I created the small basic program (myprogram). It only contains:

    argument=Program.GetArgument(1)
    TextWindow.WriteLine(argument)

    The batch file passes the argument to the program and textwindow writeline prints out the argument.

    Myprogram needs to point to the application file. To run just double click on the batch file.

    JR

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.