problem with child projects and the 'enter' key

new BookmarkLockedFalling
colinmac
Junior Member
**

colinmac Avatar

Posts: 58

Post by colinmac on May 14, 2011 12:34:02 GMT -5

Hello,

I am developing a programme that uses a main project and several child projects, each to manage a seperate table in a database. I have found that pressing the enter key when using a textbox can lead to strange behavour. The code below uses input statements, but the behaviour is the same with textboxes.

Here is the main, calling, programme called 'mainproblem.bas'
run "firstchild" , #firstchild
run "secondchild", #secondchild
wait

[firstClicked]
dummy = runbanner()
render #firstchild
wait

[secondClicked]
dummy = runbanner()
render #secondchild
wait

function runbanner()
cls
html "<h3> my problem children</h3> "
button #firstchildbutton, "first child process", [firstClicked]
button #secondchildbutton, "second child process", [secondClicked]
html "<br />"
end function

now the two child projects. firstchild.bas

rem firstchild code
[loop]
input " first child name? " ; fchild
goto [loop]
wait

and secondchild.bas

rem secondchild code
[loop]
input " second child name? " ; schild
goto [loop]
wait

Using the 'accept' button to complete a name entry works as I would expect. Pressing 'enter' to complete an entry in 'firstchild' cancels the entry. Not what I would expect but Okish. Doing the same in 'secondchild' switches everything to 'firstchild'.

Does anyone know what is going on here, and how to avoid it?

Thanks, Colin
mmiscool
Full Member
***

mmiscool Avatar

Send me a message if you want to help with a WEB OS project
Posts: 106

Check out the code wiki at http://smbisoft.com[br]The code wiki allows for multiple users to work on the same project at the same time in just basic.[br][br]SMBISoft ____888-LAN-Zoli _____ 888-526-9654
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

Post by StefanPendl on May 15, 2011 7:35:17 GMT -5

I had to change the following to make the program run:

run "firstchild" , #firstchild
run "secondchild", #secondchild
dummy = runbanner()
wait


Now the problem seems to be that we are on a form, which has several buttons, but all are currently submit buttons and there is none defined as the default button.
This seems to make the first button the default, which is the one launching the first child.

Being able to set a button as the default would allow the code to work, but I have not done this yet and there is no method for this in RB.
[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
kokenge
Senior Member
****

kokenge Avatar

Posts: 261

Post by kokenge on May 15, 2011 11:36:12 GMT -5

Hmmm??

I tried your code and as far as I can tell it works??
I removed the first wait, and placed a path on the RUN.
But other than that it worked great..



incdir$ = DefaultDir$ + "\projects\test_project\"

run incdir$;"firstchild.bas" , #firstchild
run incdir$;"secondchild.bas", #secondchild

[firstClicked]
dummy = runbanner()
render #firstchild
wait

[secondClicked]
dummy = runbanner()
render #secondchild
wait

function runbanner()
cls
html "<h3> my problem children</h3> "
button #firstchildbutton, "first child process", [firstClicked]
button #secondchildbutton, "second child process", [secondClicked]
html "<br />"
end function


You may also be interested in this: runbasic.wikispaces.com/parentChild
Last Edit: May 15, 2011 11:39:11 GMT -5 by kokenge
colinmac
Junior Member
**

colinmac Avatar

Posts: 58

Post by colinmac on May 15, 2011 12:12:01 GMT -5

Hello All,

First an apology. I cut and pasted the code fragments from my text editor, but the first line of the first programme - dummy = runbanner() - did not make the paste, and I did not spot it before posting. The code boxes have such a tiny font and my eyes are getting older all the time.

Thank you all for the quick replies. I will study them and let you know how I get on.

Colin
colinmac
Junior Member
**

colinmac Avatar

Posts: 58

Post by colinmac on May 17, 2011 18:02:04 GMT -5

Hello,

I think I have sorted out what is happening. It has nothing to do with children and parents as it turns out.

Stefan is right. RB appears to handle input elements as if they are input elements of an html form. As would happen in standard html, pressing enter in a 'text' type of input field submits the form.

By default, the 'action' field of the form appears to be the handler routine for the first button in the form, and that is where program flow goes to. But all this is not intuitive and took me by surprise!

The workaround then becomes comparatively simple. Make the first visible button on the web page point to a handler that knows where in the program the user is and renders the appropriate objects. I have called this button 'refresh' in my own application.

From a programmers perspective, if pressing 'enter' in a texbox (or input box) causes programme flow to jump somewhere else, this should be made clearer to the programmer. It would be even better of the programmer could control that jump.

Maybe textboxes should have event handlers, like buttons do, that are fired on pressing enter. The syntax would be something like:
Texbox #mybox , "my prompt" , length, [myaction]

How about it, Carl?

Colin



jerry
Junior Member
**

jerry Avatar

Posts: 86Male

An old guy that cant wait to retire!
colinmac
Junior Member
**

colinmac Avatar

Posts: 58

colinmac
Junior Member
**

colinmac Avatar

Posts: 58

Post by colinmac on Jul 6, 2014 12:54:21 GMT -5

Hi Gerry,

this is a simple as I can make my code. Make this your main project file, and save in your project directory. In this example, the project is called demoforjerry.


rem new demo project
incdir$ = DefaultDir$ + "\projects\demoforjerry_project\"
run incdir$;"route1.bas" , #route1
run incdir$;"route2.bas", #route2
run incdir$;"route3.bas" , #route3
call runbanner
wait

[route1clicked]
#handleholder = #route1
goto [refresh]
wait

[route2clicked]
#handleholder = #route2
goto [refresh]
wait

[route3clicked]
#handleholder = #route3
goto [refresh]
wait

[endAll]
cls
end

[refresh]
call runbanner
render #handleholder
wait

sub runbanner
cls
button #refresh, "" , [refresh]
rem #refresh setid("refreshbutton")

button #button1, "route 1", [route1clicked]
button #button2, "route 2", [route2clicked]
button #button3, "route 3", [route3clicked]
button #last, "end programme", [endAll]

end sub


Prepare your child processes and basic programs and store them in the same directory as the main project. In this case, they are route1.bas, route2.bas and route3.bas (I am watching the Tour de France in Yorkshire this week). Here is the route1.bas program.


rem demo for jerry route1
print "this is route 1" ;
textbox #route1box,"route 1", 20


When the main program is run the subroutine runbanner creates the navigation buttons and waits for a button to be pressed. When a button is pressed, the identity of the sub-program selected is stored in the variable #handleholder. The [refresh] routine is then called. This redraws the menu and then renders the selected sub-program.

The key to this (I think, It is some time since I worked on this) is the 'refresh' button in the navigation menu. This must be the first widget visible after the cls. This button must have as it's action the [refresh] routine that draws the actual subprogram required afresh. This button (the first one after the cls) appears to be the the default location that runbasic identifies when a textbox etc is fired.

There may be better ways to do this but this does work. It maght be slow for programs that have a lot of graphics to draw, but for text based stuff is seems OK and data is preserved as far as I can tell.

I hope it is helpful.

Colin McMurchie
jerry
Junior Member
**

jerry Avatar

Posts: 86Male

An old guy that cant wait to retire!