[Sloved] Programmly send Button Name

Post

Posted
Rating:
#1 (In Topic #1203)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi All.

I am using 46 btns to make a grid onscreen and I was wondering how do I send the Button name in the following code


Code (gambas)

  1.     If PLUDataResult.Count > 0 Then
  2.         For Each PLUDataResult
  3.              Global.pluNumber[PLUDataResult!button_number] = PLUDataResult!plulistid
  4.             Global.pluBarcode[PLUDataResult!button_number] = PLUDataResult!barcode
  5.             Global.PLUKeyName[PLUDataResult!button_number] = PLUDataResult!description
  6.             Global.PLUKeyType[PLUDataResult!button_number] = PLUDataResult!listtype
  7.            
  8.             If PLUDataResult!button_image <> "" Then
  9.                 Global.pc = Picture.FromString(FromBase64(PLUDataResult!button_image))  
  10.             Else
  11.                 Global.pc = Picture.FromString(File.Load(Application.Path &/ "fkeys/blankkey.bmp"))
  12.             End If
  13.                
  14.                 Global.ImageFromString(Global.pc, BUTTONAMEHERE, Global.PLUKeyName[PLUDataResult!button_number])
  15.                    
  16.             Select Case PLUDataResult!listtype
  17.                 Case "L" ' List
  18.                     BUTTONAMEHERE.Background = Color.Yellow
  19.                 Case "D" ' Direct sale Items
  20.                     BUTTONAMEHERE.Background = Color.Red
  21.             End Select
  22.         Next
  23.     End If    
  24.  

Where it have inserted BUTTONAMEHERE I would need to repalce that with the frmPLUList.Btn1 to  frmPLUList.Btn46

Can I some how have a const "frmPLUList.Btn" and then and the PLUDataResult!button_number to it so it would show like

frmPLUList.Btn1.Background = Color.Yellow (this is only needed at runtime) I am still looping though each option but this is taking a while to load so any ideas as how to optimize this would be most welcomed.

Andy
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
There is not enough detail in your code. It would be better if you could post some code we can run. This is how I would make 64 buttons in a grid all with the same named Group so that a single routine will handle any key pressed.

Code (gambas)

  1. HBox1 As HBox
  2. hButton As Button
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   BuildForm
  7.  
  8.  
  9. Public Sub BuildForm()
  10.  
  11.   Dim iRow, iCol, iCount, iColour As Integer
  12.   Dim sPicts As String[] = ["access", "add", "align-bottom", "align-center", "align-height", "align-left", "align-middle", "align-right", "align-top", "align-width", "apply", "archive", "attach", "audio", "battery", "book", "bookmark", "bottom", "c", "calculator", "calendar", "call", "camera", "cancel", "cdrom", "clear", "clock", "close", "color-picker", "color", "component", "computer", "connect", "copy", "cpp", "css", "cut", "database", "delete", "desktop", "development", "directory", "disconnect", "down", "download", "earth"]
  13.  
  14.   With Me
  15.     .W = 1000
  16.     .H = 475
  17.     .Arrangement = Arrange.Vertical
  18.     .Padding = 5
  19.  
  20.   For iRow = 1 To 6
  21.     With HBox1 = New HBox(Me)
  22.       .H = 56
  23.     End With
  24.     For iCol = 1 To 10
  25.       If iCount > sPicts.Max Then Break
  26.       With hButton = New Button(HBox1) As "AllButtons"
  27.         .W = 100
  28.         .H = 28
  29.         .Text = Str(iCount + 1)
  30.         .Font.Bold = True
  31.         .Picture = Picture["icon:/32/" & sPicts[iCount]]
  32.         iColour = Rand(0, 1)
  33.         .Background = [Color.Red, Color.Yellow][iColour]
  34.       End With
  35.       Inc iCount
  36.     Next
  37.   Next
  38.  
  39.  
  40. Public Sub AllButtons_Click()
  41.  
  42.   Me.Title = "Button " & Last.Text & " clicked"
  43.  
  44.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
Me["BUTTONAMEHERE"].Background = Color.Yellow

Code (gambas)

  1.  
  2. For c As Integer = 1 to 46
  3.  
  4. frmPLUList["Btn" & c].Background = Color.Yellow
  5.  
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#4
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

Me["BUTTONAMEHERE"].Background = Color.Yellow

Code (gambas)

  1.  
  2. For c As Integer = 1 to 46
  3.  
  4. frmPLUList["Btn" & c].Background = Color.Yellow
  5.  
  6.  

This one worked a treat thank-you BruceSteers once again you have come to my rescue.
Online now: No Back to the top
1 guest and 0 members have just viewed this.