jon93
New Member
Posts: 15
|
Post by jon93 on Mar 11, 2023 16:47:50 GMT
I am having difficulty understanding graphics. (Too different from old QBasic that I knew 30 years ago)
I look at examples and try to learn how text boxes etc work but the examples usually have other stuff or ingenious ways of doing things that make it too hard understand, Too hard to see what is the fundamental code.
Would somebody show me a VERY SIMPLE program making a window, with one textbox to enter a string and put it into a variable and show it on the window.? No buttons. No mouse .
Jon
|
|
|
Post by tenochtitlanuk on Mar 11, 2023 18:33:48 GMT
I'd encourage you to use Liberty BASIC- JustBASIC's 'big brother' The trial version is a free download, and if hooked you can pay for it and unlock extra features and remove the nag-screen. It has a fantastic teaching scheme with files saved as .lsn rather than .bas, which puts on screen the code of a BASIC program, allows you to run it and shows the result in a graphic window. I have a website with huge numbers of LB programs. Look at Lessons for LB/JBBig lsn file is Drawing lessonRun LB, move to directory where you saved the file, set to see .lsn files, and load. Any screen with LB code will have a notes screen, and can be run with the arrow icon or 'Run' on menu bar. Sections in the left hand side pane with '+' signs expand to show sub-sections. Hope it helps...
|
|
|
Post by plus on Mar 11, 2023 18:42:43 GMT
textbox #hndl.txt, 20, 10, 260, 25 button #hndl, "OK", [getText], LR, 5, 0 ' <<<< a button is needed to know when to process the text box WindowWidth = 350 : WindowHeight = 90 open "Text Box Demo" for window_nf as #hndl #hndl "trapclose [quit]" ' in case yopu want to use top right X button to quit wait ' until the button OK is pressed
[getText] #hndl.txt, "!contents? text$" ' get contents it is stored in a variable here it is "text$" notice "The contents of text box is: "; text$
' notice how execution falls down to [quit]
[quit] close #hndl end
Note I took the sample from JB Help on text box and modified for demo. The title was changed after the screen shot was taken. Attachments:
|
|
|
Post by tsh73 on Mar 11, 2023 19:45:10 GMT
Hello jon93 This is not "graphics" you are talking about. Graphics is the things you draw - and it pretty much the same as in old BASIC (there are pixels, and you can draw point, line, rectangle and circle ) (well and a few more things) Only difference is that you have full RGB color instead of 16 QBasic colors.
This is "GUI", graphical user interface You use pre-defined controls (windows, buttons, textboxes etc) ( btw there is a FreeForm GUI editor that allows some WYSIWIG control placing by mouse, and then generate JB program that does that. creates controls with placeholders -labels for controls events, containing just "wait" statement ). You interact with them by mouse (textbox could be clicked to make it active to start typing text) Most of the time GUI program just waits what user will do On event (such as button click) it jumps to that control handler, does that written where and again goes to wait state. Different controls have different available commands, (and in JB they are really limited) you have to consult help until you know it. (look at "GUI Programming" section in a help file)
So is not quite feasible - texbox in JB has no "text changed" event, so program will have no idea that you wrote something and it should show it to you.
Ok Minimal GUI program is empty window First line hides console window there print/input works second opens window third registers handler for closing event, it activates then you close a window next line is a comment fifth line says "we are done creating window, now let's wait for events"
Only event we written is closing at [quit.main] - it closes this window and ENDs the program (without that you likely get some orphaned unfinished Just BASIC processes in a task manager)
But this window actually allow moving, resizing, minimizing/maximizing - Windows does that for us.
nomainwin open "untitled" for window as #main print #main, "trapclose [quit.main]" 'here you add all the stuff that happen after window opened wait
[quit.main] Close #main END
now incrementally We want something happen Normal way to start something happen - click a button So let's add a button Controls should be added before OPENing window and they have starting part of the name same as window (window handle, consider it be internal name) so I add a line
BUTTON #main.btn1, "Click me", [btn1], UL, 120, 150 it says to create a button, with button handle #main.btn1 (that means it belongs to window with handle #main) with UpperLeft (UL) coordinates 120, 150 which will jump to label [btn1] then we click it.
Now we have to add that label easiest way to "do something" is to call NOTICE (build-in Windows dialog window) So button event handler is - call NOTICE to say Hello - wait for next event
[btn1] notice "Hello" wait
Full code below
nomainwin BUTTON #main.btn1, "Click me", [btn1], UL, 120, 150 open "untitled" for window as #main print #main, "trapclose [quit.main]" 'here you add all the stuff that happen after window opened wait
[quit.main] Close #main END
[btn1] notice "Hello" wait
Let's add a textbox, enter name and make button show message "Hello *name*"
We start by adding a textbox, again before OPENing window
TEXTBOX #main.txt, 110, 120, 100, 25 It handle is #main.txt - it will be used later, it's size 100x25 and it placed above button It starts empty so we could as well print "NoName" into it This is done after opening window, before first "wait"
#main.txt "NoName" (actually this is the shortcut of
print #main.txt, "NoName" - it is helpful to know that in JB, commands to controls are actually strings printed to them. So you just can print the to mainwin (==JB console) and see what's wrong. )
This code just shows "NoName" in textbox above button.
nomainwin TEXTBOX #main.txt, 110, 120, 100, 25 BUTTON #main.btn1, "Click me", [btn1], UL, 120, 150 open "untitled" for window as #main print #main, "trapclose [quit.main]" 'here you add all the stuff that happen after window opened #main.txt "NoName" wait
[quit.main] Close #main END
[btn1] notice "Hello" wait
We can edit it then program runs, but we need some commands for program to use that. Changes to be done in button handler: we should get string from textbox It ids done by issuing a command to a textbox
#main.txt "!contents? name$" meaning "get *contents* of textbox #main.txt and put it to variable s$" (and yes, I have help file open in next browser window) and add it to NOTICE command.
So the program is
nomainwin TEXTBOX #main.txt, 110, 120, 100, 25 BUTTON #main.btn1, "Click me", [btn1], UL, 120, 150 open "untitled" for window as #main print #main, "trapclose [quit.main]" 'here you add all the stuff that happen after window opened #main.txt "NoName" wait
[quit.main] Close #main END
[btn1] #main.txt "!contents? name$" notice "Hello"+" "+name$ wait
Now you can change name, and this name will be used on button press.
Last thing
You can't show stuff on the window itself - it has no commands to that! Nearest thing to it is to add а STATICTEXT to a form (text that could be changed from a program, not by the user)
STATICTEXT #main.lbl, "", 110, 180, 200, 25 we start it empty ("") so it will be invisible, and put it under the button and put (actually print) our "Hello ..." string there instead of Notice.
Here we are
nomainwin TEXTBOX #main.txt, 110, 120, 100, 25 BUTTON #main.btn1, "Click me", [btn1], UL, 120, 150 STATICTEXT #main.lbl, "", 110, 180, 200, 25 open "untitled" for window as #main print #main, "trapclose [quit.main]" 'here you add all the stuff that happen after window opened #main.txt "NoName" wait
[quit.main] Close #main END
[btn1] #main.txt "!contents? name$" #main.lbl "Hello"+" "+name$ wait
Hope this helps.
|
|
jon93
New Member
Posts: 15
|
Post by jon93 on Mar 12, 2023 0:58:41 GMT
Thank yu everyone for your help. Lots to digest, but I feel less at sea. Jon
|
|