Sver
Full Member
Posts: 145
|
Post by Sver on Apr 8, 2020 13:04:40 GMT -5
y=10
for i=1 to 3 gosub [made] y=y+40 next
open "Button Example" for window as #main wait
sub exitClicked buttonhandle$ notice "The button handle is ";buttonhandle$ end sub
[made] button #main.1, "go", exitClicked, UL, 10, y, 60, 30 return
Can I give the three buttons a different handle? Example: #main.1 , #main.2 and #main.3
|
|
|
Post by Rod on Apr 8, 2020 14:00:54 GMT -5
No, currently all controls need explicitly opened with literal values. Once established you can address controls with #Handle variables.
|
|
|
Post by Gordon Rahman on Apr 8, 2020 14:49:57 GMT -5
No, currently all controls need explicitly opened with literal values. Once established you can address controls with #Handle variables. hmmmm ... so we need to create 3 different handles for the buttons? I didn't try this yet, but a select case with 3 different handles for each button? I hate this kind of programming ...... but I like the challenge Gordon for i=1 to 3 gosub [made] next
open "Button Example" for window as #main wait
sub exitClicked buttonhandle$ notice "The button handle is ";buttonhandle$ end sub
[made] y=i*40+10 select case i case 1 button #main.1,"go.";i, exitClicked, UL, 10, y, 60, 30 case 2 button #main.2,"go.";i, exitClicked, UL, 10, y, 60, 30 case 3 button #main.3,"go.";i, exitClicked, UL, 10, y, 60, 30 end select
return
|
|
|
Post by Rod on Apr 9, 2020 1:50:02 GMT -5
I’m not sure I understand the original question now. It remains the case that each control must be created with a literal. Thereafter they can be shown, hidden , placed one on top of another, moved or addressed with a handle variable. Perhaps Sver can give us more on what he is trying to do.
|
|
|
Post by Gordon Rahman on Apr 9, 2020 4:14:45 GMT -5
Hello Rob, I agree 100%, in my example I needed more typing then just button #main.1,"go.";i, exitClicked, UL, 10, y, 60, 30 and so on, before opening the window. My English is sloppy .... so I wrote .... I hate this kind of programming (extra typing of characters) Maybe Sver didn't want to use Freeform, so he generated y? Gordon
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Apr 9, 2020 4:59:37 GMT -5
Hello Rod and Gordon
I want to make it possible to choose in a setup-window how much buttons the user needs for a interface program. It can be 1 but also 80.
Of course i can hide (79) after it, but i was wondering of other possibility before.
To show of to hide buttons in my example is not necessary, but by pressing they have to go to the right label. May be i can do something met the mouse x and y and compare it with the button x and y.
|
|
|
Post by Rod on Apr 9, 2020 5:38:08 GMT -5
Are these buttons set out in a grid? Are buttons the correct choice of control. What is the user doing with these "buttons"
As an example
dim box(64) dim note$(64) for n= 0 to 63 note$(n)="Button ";n;" help text" next
' nomainwin WindowWidth = 600 WindowHeight = 600 graphicbox #1.gb 20,30,160,160 textbox #1.tb 20, 10, 160, 20 open "Button Array" for window as #1 #1 "trapclose [quit]"
'build images #1.gb "down ; backcolor darkgray ; color lightgray" #1.gb "place 0 0 ; boxfilled 20 20" #1.gb "place 10 10 ; size 2"
'make red box for n= 0 to 70 #1.gb "color ";255-n;" ";0;" ";0 #1.gb "circle ";n/8 next n #1.gb "getbmp on 0 0 20 20"
'make grey box for n= 0 to 70 #1.gb "color ";255-n;" ";255-n;" ";255-n #1.gb "circle ";n/8 next n #1.gb "getbmp off 0 0 20 20"
'draw all the boxes for x = 0 to 7 for y = 0 to 7 #1.gb "drawbmp off ";x*20;" ";y*20 next next #1.gb "flush seg"
'start event tracking #1.gb "when leftButtonUp [processchange]" #1.gb "when mouseMove [trackit]" #1.gb "setfocus"
wait
[trackit] x=int(MouseX/20) y=int(MouseY/20) #1.tb note$(y*8+x) wait
[processchange] x=int(MouseX/20) y=int(MouseY/20) if box(y*8+x)=0 then box(y*8+x)=1 goto [showboxes] else box(y*8+x)=0 goto [clearboxes] end if
[clearboxes] #1.gb "delsegment seg" for x = 0 to 7 for y = 0 to 7 #1.gb "drawbmp off ";x*20;" ";y*20 box(y*8+x)=0 next next #1.gb "flush seg" wait
[showboxes] #1.gb "delsegment seg" for x = 0 to 7 for y = 0 to 7 if box(y*8+x)=1 then #1.gb "drawbmp on ";x*20;" ";y*20 end if next next #1.gb "flush seg" wait
[quit] close #1 end
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Apr 9, 2020 6:37:03 GMT -5
Nice example with "graphicsbuttons" in a graphicbox (or boxes)
There are more possibilities after "open" a windows. (statement)
I can make a filter for a button with If < > then goto [] , to open a port.
Thanks
|
|
|
Post by Rod on Apr 9, 2020 7:00:26 GMT -5
The more you can tell us about what you are doing the better the advice. You can only open buttons with a literal #1.b1 #1.b2, #1.b3 etc Then you can show and hide them and even change the displayed name. Perhaps you could reuse buttons?
Again is a button the correct control
maxPorts=40 dim port$(maxPorts) statictext #main.txt, "Select Port", 75, 55, 100, 20 combobox #main.portcb, port$(), [portDoubleClick], 75, 75, 100, 100 open "Get port example" for window as #main print #main, "trapclose [quit]"
' Populate the drop down list of available COM ports gosub [getPorts] wait
' Handle the combobox doubleclick event [portDoubleClick] print #main.portcb, "contents? Com$" open Com$;":9600,n,8,1,ds0,cs0,rs" for random as #com wait
[getPorts] for port = 1 to maxPorts port$(port)="" next index=1 ' now find all active ports for port = 1 to maxPorts oncomerror [trap] open "Com";str$(port);":9600,n,8,1,ds0,cs0,rs" for random as #com port$(index)="Com";str$(port) index=index+1 close #com
[trap] oncomerror next print #main.portcb, "reload" print #main.portcb, "selectindex 1" return
[quit] close #main end
|
|
|
Post by Carl Gundel on Apr 11, 2020 11:25:22 GMT -5
Nice example with "graphicsbuttons" in a graphicbox (or boxes) There are more possibilities after "open" a windows. (statement) I can make a filter for a button with If < > then goto [] , to open a port. Thanks The following will work in the next alpha release of Liberty BASIC 5. for x = 1 to 10 bh$ = "#w.b";x button #bh$, "okay", clicked, UL, 10, (x-1)*25 + 10 next x
open "test" for window as #w wait
sub clicked h$ print h$; " clicked" end sub
|
|
|
Post by Carl Gundel on Apr 11, 2020 11:53:17 GMT -5
Another example:
for x = 1 to 10 tbh$ = "#w.tb";x textbox #tbh$, 10, (x-1)*25+10, 200, 24 next x button #w.ok, "ok", clicked, ul, 10, 11*25+1 open "test" for window as #w wait
sub clicked h$ print h$; " clicked" for x = 1 to 10 tbh$ = "#w.tb"; x text$ = #tbh$ contents$() print text$ next x end sub
|
|
|
Post by metro on Apr 11, 2020 13:06:35 GMT -5
The following will work in the next alpha release of Liberty BASIC 5. for x = 1 to 10 bh$ = "#w.b";x button #bh$, "okay", clicked, UL, 10, (x-1)*25 + 10 next x
open "test" for window as #w wait
sub clicked h$ print h$; " clicked" end sub Hmmm next alpha release................torture, just a gentle reminder......... Httpget$ for the https web data. and LB5.350 (linux) lost the ability to connect to a Sqlite Db, previous builds had it.....Great work Carl Thanks
Could there be a way to access the "Button.text"? so it can be changed on the fly?
bttnText$="Orange,Apple,Pear,Pineapple,Plum,Peach,Bannana,Nectarine,Mandarin,Avacado"
DIM Btxt$(10) for n = 1 to 10 Btxt$(n) = word$(bttnText$,n,",") next n
for x = 1 to 10 bh$ = "#w.b";x button #bh$, Btxt$(x), clicked, UL, 10, (x-1)*25 + 10 next x
open "test" for window as #w wait
sub clicked h$ print (h$.Btxt(x)) end sub
|
|
|
Post by Carl Gundel on Apr 11, 2020 14:00:44 GMT -5
Could there be a way to access the "Button.text"? so it can be changed on the fly? Yeah, you can already set the button text as a string expression.
|
|