|
Post by xxgeek on Nov 30, 2022 15:18:38 GMT -5
From Lb Help CommandLine$
Description:
This special variable contains any switches that were added when Liberty BASIC was started. This is especially useful in applications executing under the runtime engine. It allows a tokenized program to receive information upon startup and act upon that information. The CommandLine$ variable can be parsed in the same way as other strings to retrieve the information. One way to extract information from the CommandLine$ is with INSTR(). The WORD$() and VAL() functions can also be used to evaluate the contents of CommandLine$.
For those who have used this command successfully: Any info, and/or examples would be appreciated.
Thanks in advance.
|
|
charley
New Member
LB User since 4.3
Posts: 8
|
Post by charley on Nov 30, 2022 23:15:13 GMT -5
Please provide example(s) Charley
|
|
|
Post by Rod on Dec 1, 2022 5:00:54 GMT -5
CommandLine$ is a system variable filled when Liberty starts up. It passes info into a program. Typically when Liberty is run as a .exe or as a .tkn. It is really giving access to standard Windows messaging. For example, if you drop a .txt file on Notepad.exe, Windows starts Notepad and passes the path and name of the .txt file so that Notepad can load it on startup. CommandLine$ gives Liberty this capability. You can read all about it here libertybasicuniversity.com/lbnews/nl92/eightyseven.html
|
|
|
Post by mknarr on Dec 1, 2022 15:32:56 GMT -5
This is rather convoluted but I have a commercial program that the person who buys it must give me their "company name". That name is then embedded into the program and appears on any printout they print and on the main window. The program the customer starts has their name embedded along with a code made up from their name The commandline$ contains that code and name and it transfers that to the main program where the main program re calculates the code again from the name and compares it to the code transmitted by the starter program. So first the program that calculates the code from the name. In this case I used the customer name "New Mexico State Fair and the code it generated is 376EC4. By this two step method I only have to make changes to the main program, rather then the customer's starting program
'Customer Code Ascii value of Owner$^2 and converted to hex
nomainwin WindowWidth = 350 WindowHeight = 195 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) BackgroundColor$ = "buttonface" ForegroundColor$ = "black" TextboxColor$ = "white" textbox #main.tb1, 10, 27, 280, 25
textbox #main.st1, 10, 67, 320, 25 bmpbutton #main.bmpb1, DefaultDir$+"\bmp\ok.bmp", [bmpb1Click], UL, 75, 107 bmpbutton #main.bmpb2, DefaultDir$+"\bmp\cancel.bmp", [bmpb2Click], UL, 205, 107
open "User Code" for window as #main print #main, "font arial 10 bold" print #main,"trapclose [bmpb2Click]" hText=hwnd(#main.tb1) calldll #user32, "SendMessageA",hText as long,_EM_LIMITTEXT as long,_ 40 as long, 0 as long, result as long 'Limit to 40 charactes.
[loop] print #main.tb1,"!setfocus" wait
[bmpb1Click] a=0 print #main.tb1, "!contents? ans$" ans$=trim$(ans$) for x=1 to len(ans$) a=a+asc(mid$(ans$,x,1)) 'a = sum of the ascii characters. next a=a^2 'a = the sum of the ascii characters squared. code$=DECHEX$(a) 'convert a to HEX. print #main.st1, code$+" "+ans$ goto [loop]
[bmpb2Click] close #main end
The starter program the customer starts would look like this.
nomainwin run "show.exe 376EC4 New Mexico State Fair" This is what the commnadline$ reads in the main program. end
The main program starts does the calculation from the Customer's name and compares it to the code received in the Commandline$
nomainwin if CommandLine$="" then end 'In case the customer tries to start the main program instead of the starter program 'Check to find show.exe in CommandLine$ and remove. if word$(CommandLine$,1)="showsec.exe" then CommandLine$=trim$(afterlast$(CommandLine$,".exe")) 'Remove OwnerCode$ and compare code to Owner$ OwnerCode$=upto$(CommandLine$," ") Owner$=trim$(replstr$(CommandLine$,OwnerCode$,"")) OwnerCode=HEXDEC(OwnerCode$) 'Convert the Owners Code to decimal. OwnerCode=int(SQR(OwnerCode)+.5) 'Get the square root and round up. This is the sum of the ascii value calculated from the owner's code. for x=1 to len(Owner$) 'Now from the Owner Name that was in the CommandLine$ a=a+asc(mid$(Owner$,x,1)) 'get sum of the ascii value of the letters next if a<>OwnerCode then 'and compare it to the sum of the ascii value of the owner's code. notice "FATAL ERROR!"+chr$(13)+"It appears the program has been tampered with and is now disabled!!" end end if
And if the match the main program continues to run
|
|
|
Post by xxgeek on Dec 1, 2022 16:16:06 GMT -5
Thanks for the replies guys. Much appreciated.
The reason I've asked, and posted this command of the day, was because I had some difficulty getting it to work for me.
I know this is the LB forum, but most of what I write is for JB, then if I can, I re-write another version to work in LB.
As you all know JB does not have an option to create an exe file. If you've paid attention to the JB forum posts, you'll know I overcame that by copying the dll's sll's and jbrun2.exe to a dir, created the tkn and added it to the dir, then renamed the jbrun2.exe to the name of the tkn. To create the exe file I wrote a VB script to "effectively" hit the [enter] key when the "save as" window appears, then do the same when the notification window appears to let the user know where the tkn was saved. No user intervention required, other than to select a .bas file to convert to exe.
In order to create the exe I used iexpress (a built-in windows app)to "kind of" zip up the folder, and create a self extracting exe pointing to the new exe. The thing is, when this exe is executed it is put in a 'temp' dir, and that dir gets deleted when the program exits. (because it is a 'temp' dir.
Using CommandLine$ I should be able to have the program look at where it is using DefaultDir$, and if it is in a 'temp' dir, then copy the dir to somewhere else, like the desktop or c:\Program Files (x86), then run the exe again from there, and end itself. Make sense?
Why was it a problem in the temp dir? If the program creates any files in that temp dir, they are lost when it gets deleted - as the program exits. Many programs create files so making the exe using iexpress is useless for those, and I want to make it useful for ANY exe created with iexpress.
Examples really help, so keep em coming(for everyone else, I have what I need now), thanks again.
|
|
|
Post by tsh73 on Dec 1, 2022 18:15:15 GMT -5
No This is
exactly documented way of creating EXE file in JB. (actually LB works the same, but automated via menu)
Or do you mean "create running program as SINGLE exe file (no DLL/SLL visible)"? But why bother?
|
|
|
Post by xxgeek on Dec 1, 2022 19:32:45 GMT -5
Or do you mean "create running program as SINGLE exe file (no DLL/SLL visible)"? But why bother? I do mean a single file. That's what iexpress does, turns the folder with all the files into a single executable file. Why would anyone want the single file as apposed to a folder? Easier to distribute. Easier to execute. (no need to open a folder to execute. A folder full of exe files is a lot better easier to deal with in code than a folder full of folders with exe files, tkn files, dll's and sll's especially when automating. I've been working on a huge program for the past 2 years, since I installed JB the first time. All the little apps you've seen me post are little pieces of that whole, posted as I create them on the forums as backup, and in case I don't live long enough to finish, at least someone can take over. I also have big plans for cundo's search engine under my hat. My main goal with JB is to help all those who start using it, to learn JB with more ease than I did. I'm just an old guy with time on my hands, and since I got JB free, I want to help others learn too. The more people (like us, older, and wanting to get back into coding basic) that start with JB, the more that will want to buy LB with the better features. For some updated information on CommandLine$ see this thread... libertybasiccom.proboards.com/threads/recent/352
|
|