[Sloved] Programmly send Button Name

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

[Sloved] Programmly send Button Name

Post by AndyGable »

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


    If PLUDataResult.Count > 0 Then
        For Each PLUDataResult
             Global.pluNumber[PLUDataResult!button_number] = PLUDataResult!plulistid
            Global.pluBarcode[PLUDataResult!button_number] = PLUDataResult!barcode
            Global.PLUKeyName[PLUDataResult!button_number] = PLUDataResult!description
            Global.PLUKeyType[PLUDataResult!button_number] = PLUDataResult!listtype
           
            If PLUDataResult!button_image <> "" Then 
                Global.pc = Picture.FromString(FromBase64(PLUDataResult!button_image))  
            Else 
                Global.pc = Picture.FromString(File.Load(Application.Path &/ "fkeys/blankkey.bmp"))
            End If
                
                Global.ImageFromString(Global.pc, BUTTONAMEHERE, Global.PLUKeyName[PLUDataResult!button_number])
                    
            Select Case PLUDataResult!listtype
                Case "L" ' List
                    BUTTONAMEHERE.Background = Color.Yellow
                Case "D" ' Direct sale Items
                    BUTTONAMEHERE.Background = Color.Red
            End Select
        Next
    End If    


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
Last edited by AndyGable on Tuesday 12th March 2024 6:22pm, edited 1 time in total.
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Programmly send Button Name

Post by cogier »

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.

HBox1 As HBox
hButton As Button

Public Sub Form_Open()

  BuildForm

End

Public Sub BuildForm()

  Dim iRow, iCol, iCount, iColour As Integer
  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"]

  With Me
    .W = 1000
    .H = 475
    .Arrangement = Arrange.Vertical
    .Padding = 5
  End With

  For iRow = 1 To 6
    With HBox1 = New HBox(Me)
      .H = 56
    End With
    For iCol = 1 To 10
      If iCount > sPicts.Max Then Break
      With hButton = New Button(HBox1) As "AllButtons"
        .W = 100
        .H = 28
        .Text = Str(iCount + 1)
        .Font.Bold = True
        .Picture = Picture["icon:/32/" & sPicts[iCount]]
        iColour = Rand(0, 1)
        .Background = [Color.Red, Color.Yellow][iColour]
      End With
      Inc iCount
    Next
  Next

End

Public Sub AllButtons_Click()

  Me.Title = "Button " & Last.Text & " clicked"

End
User avatar
BruceSteers
Posts: 1580
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Programmly send Button Name

Post by BruceSteers »

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


For c As Integer = 1 to 46

frmPLUList["Btn" & c].Background = Color.Yellow

Next
If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Programmly send Button Name

Post by AndyGable »

BruceSteers wrote: Tuesday 12th March 2024 2:45pm Me["BUTTONAMEHERE"].Background = Color.Yellow


For c As Integer = 1 to 46

frmPLUList["Btn" & c].Background = Color.Yellow

Next
This one worked a treat thank-you @BruceSteers once again you have come to my rescue.
Post Reply