|
Post by dagnabitboy on Sept 23, 2020 12:42:44 GMT -5
I want to modify an existing LB program so that it accepts some input parameters from the command line, and I want to run it such that it doesn't open a window. I vaguely remember doing this a long time ago, so I'm pretty sure it's possible, but my memory just might be wrong!! If anyone can share knowledge they might have of this it would be most appreciated. Thanks!
|
|
|
Post by Chris Iverson on Sept 23, 2020 13:37:29 GMT -5
If you mean LB's main console window, that opens by default when executing an LB program, having the "nomainwin" directive anywhere in the program should suppress that.
If you mean an actual GUI window being opened with the OPEN command, then there's no way to avoid that besides modifying the program and recompiling it.
|
|
|
Post by dagnabitboy on Sept 23, 2020 14:02:29 GMT -5
Thanks Chris that should work. I also am trying to learn how to actually input a command/string from the command line. For example, if I run my lb program like this: "myprog string1, string2"; I want to be able to input the strings and use them. I realize now my original question was poorly worded!! Thanks
|
|
|
Post by Rod on Sept 23, 2020 15:00:05 GMT -5
CommandLine$ is the system variable that will hold any parameters passed when the program is called. There are examples in the LBPE and the help file.
|
|
|
Post by dagnabitboy on Sept 23, 2020 15:07:26 GMT -5
Thanks Rod! I looked high and low for that, I was pretty sure I'd used it before, but it was many years ago. Much appreciated!!
|
|
|
Post by Brandon Parker on Sept 23, 2020 17:19:50 GMT -5
Here is a simple command-line parser that I have used in the past. All you have to do is call the function with the data following the switch that you wish to retrieve. Also, make sure the command-line ends with " -" when you construct it and call your LB program. In the code below, the CommandLine$ variable has been specifically set up with nonsense switches that mean nothing to LB, but can be used to send information into an LB program via the command-line when the program is sarted.
CommandLine$ = "F:\SomeProgram.exe F:\SomeProgram.tkn -f F:\SomeProgram.bas -h alpha beta -q gamma -r Renegade!! -n Test_Was_Successful!!!!!!!! -z Failure!!!!!!!! -" Print CommandLineParser$("-f") Print CommandLineParser$("-q") Print CommandLineParser$("-r") Print CommandLineParser$("-n") Print CommandLineParser$("-z") End
Function CommandLineParser$(switch$) If Instr(CommandLine$, switch$) > 0 Then CommandLineParser$ = Trim$(Mid$(CommandLine$, (Instr(CommandLine$, switch$) + Len(switch$)), _ (Instr(Mid$(CommandLine$, Instr(CommandLine$, switch$)), " -")) - 2)) Else CommandLineParser$ = "Switch not found!" End If End Function
{:0)
Brandon Parker
|
|
|
Post by tsh73 on Sept 24, 2020 4:00:36 GMT -5
Here's modification what doesn't need trailing " -"
EDIT this one puzzled me (for a while) I know by heart "MID$(a$,i,1)" so last parameter is LENGTH so - how does Mid$(CommandLine$, switchStart, switchEnd) supposed to work if switchEnd = Instr(...), that is, POSITION?
It happened that it is actually switchEnd = Instr(Mid$(CommandLine$, switchStart), " -") So it is POSITION in the substring (MID$) starting from switchStart that is, actually LENGTH from found position to switchStart. (+/- 1 character) Clever bit.
CommandLine$ = "F:\SomeProgram.exe F:\SomeProgram.tkn -f F:\SomeProgram.bas -help alpha beta -q gamma -r Renegade!! -n Test_Was_Successful!!!!!!!! -z Failure!!!!!!!!?" Print CommandLineParser$("-f") Print CommandLineParser$("-q") Print CommandLineParser$("-r") Print CommandLineParser$("-help") 'more then single symbol Print CommandLineParser$("-www") 'not found Print CommandLineParser$("-n") Print CommandLineParser$("-z") 'last switch, should not drop last symbol End
Function CommandLineParser$(switch$) switchStart = Instr(CommandLine$, switch$) If switchStart > 0 Then switchStart = switchStart + Len(switch$) switchEnd = Instr(Mid$(CommandLine$, switchStart), " -") if switchEnd = 0 then switchEnd = len(CommandLine$) 'so we don't need trailing " -" CommandLineParser$ = Trim$(Mid$(CommandLine$, switchStart, switchEnd)) Else CommandLineParser$ = "Switch not found!" End If End Function
|
|
|
Post by dagnabitboy on Sept 27, 2020 14:48:28 GMT -5
Wow! I leave for a few days and when I come back there are lots of excellent tips! Thank you everyone!
|
|