RUN program control

new BookmarkLockedFalling
kokenge
Senior Member
****

kokenge Avatar

Posts: 261

Post by kokenge on Feb 10, 2010 10:48:13 GMT -5

I have a two programs.
1. RUNNING program uses the render to run a program
2. RUNNED is the program being run.

The first program runs the second. The second program has the option of doing something, or exiting back to the first. In my case the second program can update some records, or not. When the first program is returned control, it should display stuff the second program did.

PROBLEM: The second (RUNNED) program can Exit ok. However it Does Something, it should fire and event to return to the first.
It always returns to the Run Basic Login screen.

What am I doing wrong???

Using Firefox and XP. In using the layout_project in RB.

The Running Program

' -----------------------------------------
' test.bas
' RUNNING program
' -----------------------------------------

' CSSClass ".hide", "{visibility: hidden; height:0px; bprder:none}"
projectDir$ = "layout_project"
incdir$ = DefaultDir$ + "\projects\" + projectDir$ + "\"

' ----------- Main code --------------------
[main]
cls
html "Hello I'm at main<P>"
button #run, "Run",[doRun]
html "<hr>"
wait

' -----------------------------
' Run a program
' -----------------------------
[doRun]
button #c, "Main", [main]
#c setkey(rowid$)
#c setid("clickThis")
#c cssclass("hide")

exitBack$ = "clickThis"
gosub [runProg]
wait

' -------------------------------------------
' gosub to Run the program
' UserInfo$ tells the RUNNED program what
' the ID of the RUNNING button you wanna push
' -------------------------------------------
[runProg]
UserInfo$ = "clickThis"
run incdir$;"aRun.bas",#include
render #include
RETURN


The RUNNED (child) program


' ------------------------------------------
' aRun.bas
' RUNNED program
' ------------------------------------------

runExit$ = UserInfo$

' -----------------------------------------
' JS to fire event
' -----------------------------------------
html "<script type='text/javascript'>

function fireEvent(obj,evt)
{
var fireOnThis = obj;
if( document.createEvent ) {
var evObj = document.createEvent('MouseEvents');
evObj.initEvent( evt, true, false );
fireOnThis.dispatchEvent(evObj);
} else if( document.createEventObject ) {
fireOnThis.fireEvent('on'+evt);
}
}
</script>
"

html "

Hello I'm in the run program
The exit in main is at ";runExit$
html "<P>"


button #acd, "Do Something", [doClick]
#acd setid("xx")

' -------------------------------------------
' Button to return to RUNNING program
' -------------------------------------------
button #exit, "Exit",[doExit]
#exit setid("exitMe")
html "<script>
document.getElementById('exitMe').name = document.getElementById('";runExit$;"').name;
</script>"

wait

' ----------------------------------------
' Button to do something and then
' return to the RUNNING program
' ----------------------------------------
[doClick]
html "<P>Do Something <P>"

html "<script>
fireEvent(document.getElementById('";runExit$;"'),'click');
</script>"

wait

[doExit]
wait



Thanks for the help...
Have a great day..
Dan
metro
Full Member
***

metro Avatar

Posts: 207

Post by metro on Aug 2, 2025 21:55:59 GMT -5

Feb 10, 2010 23:48:13 GMT 8 kokenge said:
I have a two programs.
1. RUNNING program uses the render to run a program
2. RUNNED is the program being run.

The first program runs the second. The second program has the option of doing something, or exiting back to the first. In my case the second program can update some records, or not. When the first program is returned control, it should display stuff the second program did.

PROBLEM: The second (RUNNED) program can Exit ok. However it Does Something, it should fire and event to return to the first.
It always returns to the Run Basic Login screen.

What am I doing wrong???


G'Day Dan, did you find a work around for this?

I have just started converting an LB program I created for my son to RB thanks to your your codeGen program it has been a breeze so far
and rather than create a long slab of code I have elected to cut it up into child processes
but I am as rusty as heck having not done any coding for a few years.

I too get the child program to run but on exit drop out to the RB login

Thanks for the help

Laurie
Last Edit: Aug 2, 2025 21:56:34 GMT -5 by metro
Intel Core2 QUAD CPU @2.54 x 4 Mint Linux 19.3 Mate
meerkat
Senior Member
****

meerkat Avatar

Posts: 250

Post by meerkat on Aug 3, 2025 12:50:37 GMT -5

Howdy Lauri.

Ya.. I found a workaround.
The trick is to put the [Exit] button in the parent before running the clild.
The [Exit] button tells the user to exit the program. Since it's simply a button in the parrent you can have the [Exit] button go to any tag in the parent. Or you could actually make it exit if you wanted.

Here is an example from my client.bas program.
It list all the clients and each client on the list has a [Brief] button for information. They can click the [Brief] button and it goes to [clientBrief] tag.
It displays a button that says to [Exit Brief] and since the button is in the parent it can go to any tag, and in this case it goes back to the [clientList]. That clears 'CLS' the screen and brings back the client list.

the [mntRun] is used for all programs in the parent you want to run.
It runs the child. I pass a bunch of stuff for security, so it knows what security the clild has and what client number it's producing the bried for. You may not need to pass anything and can delete those lines of code.

I have had child programs that run another child so the routine works for multiple child levels.
The code to do this should be in the RBgen program you used to generate your code.

Have a great day..
Good luck.. Any problems.. let me know.
Dan
' ---------------------------------------------
' tag for clientBrief
' ---------------------------------------------
[clientBrief]
cls
clientNum$ = EventKey$

html " "
button #ex, "Exit Brief", [clientList]
#ex cssclass("extBtn")
html "</TD></YT></TABLE>"
prog$ = "clientBrief.bas"
html "<center>"
goto [mntRun]
wait

' -------------------------------------------
' Run program
' -------------------------------------------
[mntRun]
runProg$ = "event"
runProgData$ = clientNum$ + " "
UserInfo$ = loginUserNum$;"|";loginUserName$;"|";loginCanMaint$;"|";loginKeyKeeper$;"|";runProg$;"|";runProgData$;"|Y|";" |";runExit$
html "<HR>"
incdir$ = DefaultDir$ + "\projects\foodbank_project\"
run incdir$;prog,ドル#include
render #include
wait


---------- Running a child from a top manu program ----------------
If your parent program is the root program such as a main menu screen then you can have a
button for each program in the menu.
Then this works ok where prog$ is the program name such as a.bas.
incdir$ = DefaultDir$ + "\projects\your_project\"
run incdir$;prog,ドル#include
render #include
The rendered program needs to have need a few things.
1. You cannot have a title in a child.
One if the variables in the UserInfo$ words is for runPass$ = "Y" that you can get.
if runPass$ <> "Y" then titlebar "client System" ' here if it's a child there is no title.

2. I pass another variable in the UserInfo$ words to pass a runExit$
if runExit$ = "" then runExit$ = "exitApp"
So the runned program needs to know it's a child.
Here is the prepared [Exit] in the runned program.
It uses JavaScript to know how many parents to move up, and in the runned program it
needs to go up -1.
Here is your [Exit] button in the child.

html "</TD><TD ALIGN=center>"
button #exit, "Exit",[doExit]
#exit setid("exitMe")
#exit cssclass("extBtn")
if runPass$ = "Y" then
html "<script>
document.getElementById('exitMe').name = document.getElementById('";runExit$;"').name;
</script>"
end if

' -----------------------------------------
' Get outta here
' -----------------------------------------
[doExit]
html "<script language='javascript' type='text/javascript'>
var a = history.length;
a = a - 1;
window.open('','_parent','');
window.close();
history.go(-a);
</script>"
wait



Last Edit: Aug 3, 2025 17:56:46 GMT -5 by meerkat
metro
Full Member
***

metro Avatar

Posts: 207

Post by metro on Aug 3, 2025 18:45:00 GMT -5


I have had child programs that run another child so the routine works for multiple child levels.
The code to do this should be in the RBgen program you used to generate your code.



Thanks Dan once again.
Looks Like I should spend some time dissecting RBGen to get more tips.
I touched on Divs yesterday to layout the page better and may have found scope issues
branches not found with RB Divs not tested using html "<div> ***block of code*** </div>"
More than likely something I don't understand yet ...more testing today.
I appreciated the help...

Laurie
Intel Core2 QUAD CPU @2.54 x 4 Mint Linux 19.3 Mate
meerkat
Senior Member
****

meerkat Avatar

Posts: 250

Post by meerkat on Aug 3, 2025 19:26:40 GMT -5

Howdy again..

divs are very handy. I use them a lot as a place holder for stuff.
For example html "<div id='errMsg'></div>" is a nice way to show errors in the same place all the time.
I'm more inclined to put errors in a section of a <table>. So if I have a <table> with a heading like
html "<table><TR bgcolor=wheat><td colspan=3>This is the heading</TD></TR>"
html "<TR><TD id = 'errMsg' colspan=3></td></tr>" ' this is where errors show up
html "<TR><TD>col<br>1</TD><TD>col<BR>2</TD><TD>col<br>3</TD>"
Now I have a place in the table to report errors.

To place stuff in the errMsg area, you can use javascript.
Browsers use JS document.getElementById('errMsg') to find the location of errMsg on the users browser.
So to place the message "You got errors" in that location use the following.
errMsg$ = "You got errors"
html "<script> document.getElementById('errMsg').innerHTML = '";errMsg$;"';</script>"
A tip that may save you a big headache is to use chr(96) to enclose the message instead of the single quote.
If you have a single quote in the errMsg$ it will cause problems. For example errMsg$ = "You're Wrong again"
Using a 'back quote' chr(96) makes it possible to put entire <table> info or whatever in 'errMsg'. So I use
html "<script> document.getElementById('errMsg').innerHTML = ";chr$(96)
html errMsg$
html chr$(96);"</script>"

if the field you are trying to place data into is a <input field you can give it a id.
Then use .value instead of .innerHtml .
custNum$ = "123"
html "<script> document.getElementById('custNum').value = '";custNum$;"';</script>"


Good luck.. Hope this helps.


Last Edit: Aug 4, 2025 3:38:13 GMT -5 by meerkat
meerkat
Senior Member
****

meerkat Avatar

Posts: 250

Post by meerkat on Aug 4, 2025 5:57:19 GMT -5

More info on divs that you may be interested in.
You can also use divs to run other programs.
For example, if you have html "<div id='prog'></div>" you could put a program in it.
Again I kinda like a <table> with <td id='prog'> because I have more control on size and location.
Possible with <div>, but a little more difficult.
To place your code in the 'prog' location;
html "<script> document.getElementById('prog').innerHTML = chr$(96)
html "Hello World"
html "<IMG SRC='"; imgPath$; photoId$; "' height=400>" ' even photos
button #ex, "Exit", [exit]
wait
[exit] ' to exit simply set the div you are in to blank.
html "<script> document.getElementById('prog').innerHTML = '' </script>"
end
html chr$(96);"</script>"
wait

Too much fun..
Good luck..


metro
Full Member
***

metro Avatar

Posts: 207

Last Edit: Aug 4, 2025 7:04:45 GMT -5 by metro
Intel Core2 QUAD CPU @2.54 x 4 Mint Linux 19.3 Mate
meerkat
Senior Member
****

meerkat Avatar

Posts: 250

Post by meerkat on Aug 4, 2025 8:26:40 GMT -5

Howdi Lauri!

Hmmmm! Interesting.. The reason I started using RB is because of how complicated LB was and how simple RB was.
Ya.. I need RB for the web. For me even simple stuff was a lot easier in RB. For example screen layout was complex just giving it every pixel place and pixel size was a pain. I like <tables> since they float to fit everything. Just doing a simple list with [Add], [Change], and [Delete] for 20 or 30 items was complex. Even simple scrolling of a lot if input items on a screen in LB is almost impossible.
I even wrote a LBgen program long ago that generates LB code. It should still be on the LB forum somewhere. You'll see how it had to work around all the limitations of LB.

The most comples thing in any web language is laying out the form, especially <table>s. I use Vpage and layout the form, and tables. Then take the code it generates to lay out the form and modify it with RB html statements.

Don't know if you used PHP or Python but RB is a lot easier.

Hang in there..
If you have something you need help with, let me know and I can send you the code to do what you are trying to do.

Have a great day...
Dan
metro
Full Member
***

metro Avatar

Posts: 207

Post by metro on Aug 5, 2025 9:18:26 GMT -5

Don't know if you used PHP or Python but RB is a lot easier


Thanks Dan, my issue is no coding background
Html and scripts are the only hiccup ATM, it's quite easy to pickup
It's just time consuming in the beginning.
I completed one simple contact DB today
More ambitious project over the next few days creating a brew record system for the beer excise tax brewers have to pay here in OZ.
Currently stored in Excel.

Thanks for the help so far.

Laurie
Intel Core2 QUAD CPU @2.54 x 4 Mint Linux 19.3 Mate