PDA

View Full Version : Script linking... Like "Include"?



ISAWHIM
29-09-2008, 05:01
Is there a way to use a script inside a script? (Yes, I am looking to add more confusion.)

This is what I am trying to do.

I have one script which I call "MAIN", it uses only UI, INET, and INI. (Just to keep it simple.)

This part of the program uses the UI to provide quick feedback about the connections and available files. (File1, File2, File3)

The file-list was originally downloaded with the simple INET_UrlDownload(), and read as an INI file, with the list of links to the other available files.

What I now want to do... Is allow the MAIN program to pull text from another downloaded file, and include that script as if it were part of this same script. (EG, without opening another UI.) It would be fine if it opened a child-window inside the main window, or if it created another window with the new options. But I do want to keep this all in one window, if possible.

The "Included" script would not be part of the main program, as it would change often. The UI would remain the same, as the new scripts would contain the required code/modules required to run them.

What I have to do now, is create a separate program for each item, or create one large program, with all possible variations available, even if they are not used. Some of these files are just direct file downloads, others require input prior to activation, such as passwords to unlock/decrypt, install paths, choice selections.

The closest thing I can think-of, would be a scripted-include. (Unlike a "USES" which is loaded prior to operation, an include would not load until called, and the script/text inside, would function as if it were originally part of the code, but could have its own "USES".)

If this is not a feature, or ability... Can you move this to the suggestions area?

Michael Hartlef
29-09-2008, 05:46
Hi Jason,

to load a script file on command, that is not possible right now. I made that request some time ago. The structure of thinBasic doesn't allow the implementation right now but Eros was so kind and added an extra INCLUDE functionality so you can add scripts without knowing their names. Then you can use the CALL command to run functions with predefined names.

Please look at the simple plugin functionality I did. I think that this could be usefull for what you are trying to do.

Cheers
Michael

ISAWHIM
29-09-2008, 07:32
Ok, so I could simply reboot the window/program, and now, once those exist... They will load.

EG...

MAIN downloads flie1, file2, file3, and already has the code to INCLUDE *... but nothing happens, because when it was first loaded, file1-3 were not present... But now that it reboots, with the files there, they all get loaded. (He said "Get loaded")

Does this also rule-out launching another app/thinBasic script, from MAIN?

I saw that I can pass parameters to a script as it loads, but can one script launch another? (I might be able to ghetto-rig a loopback IP for communication. I don't like API calls for form to form communication. Plus, that opens the window for the possibility of remote communication in the future, if it is desired.)

Again, for now, it will be no trouble for me to tell them that they have to reboot manually, or launch the separate process, once downloaded. It is just easier for them, to do it all from that MAIN controller.

I recall using a "Shell" command, and/or "AppActivate"... I think it was "Shell"... Because I remember passing values to a CLI of winzip, since VB did not have a zip tool. (I have spent all day digging through all the pages of the help-files, looking for anything I could use to do this. Figured that it would also come in handy for launching MSIE for dynamic created pages also. That would reduce my GUI demand of thinBASIC, because I could just run it as a HTML server. Like a mini-PHP.)

Michael Hartlef
29-09-2008, 07:44
Yes, via a shell execute scripts can run other scripts, but they run in seperate processes and so don't know each other.

Michael Hartlef
29-09-2008, 07:45
Btw. thanks for the karma :)

ISAWHIM
29-09-2008, 10:07
No thanks needed... your karma was earned. (I know, people prefer cash, but with the exchange rate now... I can only afford karma.)

This is what I am using... (The short version, for lack of better options at the moment.)


DECLARE FUNCTION ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As DWORD, ByVal lpszOp As STRING, _
ByVal lpszFile As STRING, ByVal lpszParams As STRING, _
ByVal LpszDir As STRING, ByVal FsShowCmd As LONG) As DWORD

DIM hRetVal AS DWORD
Dim hWnd As DWORD ' This is the normal window handle

hRetVal = ShellExecute(hWnd, "Open", "programs.ini", , "C:\Documents and Settings\USER\Desktop\TestServer\", 1)

I changed the sample code values from VB LONG to DWORD, because I think I remember the values are unsigned? (I may be wrong there, they may need to be LONG... Maybe VB LONG was unsigned... I forget.)

http://support.microsoft.com/kb/170918

The "1" is "Const SW_SHOWNORMAL = 1"... Minimized, Maximized, Hidden, were the other possible values, I think.

This only runs the associated program with the file. Fine for EXE.

The EMPTY ", ," is for passing commands to the file... Which I used to run winzips CLI tool.

Michael Hartlef
29-09-2008, 10:15
Yip, woudl be one way or from the OS module, the OS_SHELL command.

n = OS_Shell(Command[, WindowStyle[, Mode]])

ErosOlmi
29-09-2008, 10:56
Jason,

thinBasic has OS module that wraps and extend some operating system functionalities.
See OS_Shell help at http://www.thinbasic.com/public/products/thinBasic/help/html/os_shell.htm

So just add

USES "OS"
at the beginning of your script and you will be able to use OS_Shell function plus all OS module functions.

Ciao
Eros

ErosOlmi
29-09-2008, 11:05
Hi again Jason.

Here an example with your script:


USES "OS"

DIM hRetVal AS DWORD

hRetVal = OS_ShellExecute("Open", "programs.ini", , OS_GetSpecialFolder(%CSIDL_DESKTOP) & "\TestServer\", 1)





I've used OS_GetSpecialFolder (http://www.thinbasic.com/public/products/thinBasic/help/html/os_getspecialfolder.htm) function to get the path to the desktop because that directory is not fixed but can change from system to system.

Eros

ISAWHIM
29-09-2008, 20:48
Thanks again...

I just hard-coded that link, for testing that specific file. (The program will actually operate from the selected install path.)