|
Post by meerkat on Mar 7, 2019 15:14:22 GMT -5
If I have several buttons going to the same [tag], is there a what to know what button was clicked?
Is there a way to give buttons some kind of ID that can be accessed?
Thanks for the help.. Dan
|
|
|
Post by Chris Iverson on Mar 7, 2019 15:59:45 GMT -5
Not if you're using branch label event handlers. Subroutine handlers include a parameter that contains the handle of the control that generated the event.
If you need to use branch label event handlers, then instead of setting both buttons to use the same branch label handler, set them to use separate handlers that set a variable to a unique value, then GOTO a common branch label that checks the variable, and does the processing you need.
|
|
|
Post by meerkat on Mar 7, 2019 16:55:22 GMT -5
Thanks Chris.. Sorry to hear that. I have about 30 buttons all doing basically the same thing. Especially useful when listing a lot of data from a database or something. Too bad there isn't some way to dynamically generate buttons with and ID, and variables for column,row, width and height. something like : for i = 1 to numOfRecords x = 1 y = y + 30 w = 100 h = 25 button #main.xxx, id=i "xxx", [doxxx] ,UL ,x,y,w,h next i
maybe it's possible to do an eval on it.. I dunno
So I guess I'll need to write a lot of code to list stuff on a page.
Dan
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Mar 7, 2019 17:22:08 GMT -5
Use Sub instead. They can receive the Handle and you just use Select Case.
|
|
|
Post by metro on Mar 7, 2019 19:32:37 GMT -5
Use Sub instead. They can receive the Handle and you just use Select Case. a quick cut and paste example 'Choose 5 common MS Applications App$(1) = "Notepad.exe" App$(2) = "MSPaint.exe" App$(3) = "Calc.exe" App$(4) = "sndrec32.exe" App$(5) = "Spider.exe" nomainwin WindowWidth = 200 WindowHeight = 300 UpperLeftX = int((DisplayWidth - WindowWidth)/2) UpperLeftY = int((DisplayHeight - WindowHeight)/2) menu #main, "&Options", "E&xit", [EndDemo] button #main.app1, "Notepad", App2Run, UL, 30, 20, 110, 20 Button #main.app2, "MS Paint", App2Run, UL, 30, 50, 110, 20 button #main.app3, "Calculator", App2Run, UL, 30, 80, 110, 20 button #main.app4, "Sound Recorder", App2Run, UL, 30, 110, 120, 20 button #main.app5, "Spider", App2Run, UL, 30, 140, 120, 20 open "Launching Applications" for Window as #main #main "Trapclose [EndDemo]" wait [EndDemo] close #main end sub App2Run handle$ app = val(right$(handle$, 1)) select case app case 1 notice "one" case 2 notice "two" case 3 notice "three" case else notice "other number" end select end sub'untitled.bas alycesrestaurant.com/lbpe/Coding%20With%20Subs.html
|
|
|
Post by Rod on Mar 8, 2019 7:10:13 GMT -5
Yep sub handlers really shorten the code. Also we might be able to dynamically write new controls in LB5, just hoping. In the meantime graphic buttons can pack a lot into a small space.
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
|
|