Dynamically create buttons using code

I want to create a grid in a form in vb6 buttons. I am working on redundancy, so I would suggest that generating buttons for each selection (e.g. A1, E7, etc.) is the way to go.

However, I could not figure out how to do this.

I am working on a reservation system. Therefore, I would like the grid to be formed from the number of places entered through the database (it should not matter, but what is hay).

So, for example, if the total number of places was 100, I would like the form to create a grid of 10x10 buttons. When one of the buttons is pressed (each of them is unique), I could reserve them by changing / adding a place to the reserved table in the database.

tried to find solutions everywhere, but it seems that in VB6 there is no answer to this question.

+3
source share
1 answer

See below what you ask for:

'1 form with
'  1 commandbutton: name=Command1  index=0
Option Explicit

Private Sub Command1_Click(Index As Integer)
  Caption = CStr(Index)
End Sub

Private Sub Form_Load()
  Dim lngIndex As Long
  For lngIndex = 1 To 100
    Load Command1(lngIndex)
  Next lngIndex
  For lngIndex = 0 To Command1.UBound
    With Command1(lngIndex)
      .Caption = CStr(lngIndex)
      .Visible = True
    End With 'With Command1(lngIndex)
  Next lngIndex
End Sub

Private Sub Form_Resize()
  Dim lngIndex As Long
  Dim sngWidth As Single, sngHeight As Single
  Dim lngRow As Long, lngCol As Long
  sngWidth = ScaleWidth / 10
  sngHeight = ScaleHeight / 10
  For lngIndex = 0 To Command1.UBound
    lngRow = lngIndex \ 10
    lngCol = lngIndex Mod 10
    Command1(lngIndex).Move lngCol * sngWidth, lngRow * sngHeight, sngWidth, sngHeight
  Next lngIndex
End Sub

Be careful, since a lot of control over 1 form can significantly slow down the work.

If the seat layout is a good mesh, you might be better off using a mesh control (msflex)

Another option is to upload an image of the location map and allow the user to click on the image, after which you can use the X and Y coordinates to determine which location was clicked ... this way you can also use different colors in the image and get a color that user clicked to preselect seat type

+2
source

All Articles