0 Replies - 957 Views - Last Post: 09 June 2014 - 10:44 AM Rate Topic: -----

#1 luczadora  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-June 14

Populating Variables with Combobox Control Arrays

Posted 09 June 2014 - 10:44 AM

Hi everyone,

I'm creating a dynamic form using VB6 where the number of labels and combo boxes is dependent on the number of levels.
I've figured out how to make the dynamic array for the combo boxes but I can't connect a _Click() sub to the new "OK" button I've created.

In addition, in the new "OK" sub that I would like, I want to populate an array called rankLayers() with the selections from the combo boxes made in the FormLoad() Sub.

Any and all help and suggestions would be greatly appreciated !
Private Sub Form_Load()
'Variable defintions----------------
Dim i As Integer:       Dim j As Integer:          Dim rank As Integer:
Dim mL As Integer:      Dim objLabel As label:     Dim objOK As CommandButton:
Dim objCmb(0 To 9) As ComboBox:

Me.height = 2000 + 500 * (maxlevels + 2)
Me.width = 4800

For i = 0 To maxlevels - 1
    Set objLabel = frmRankStrata.Controls.add("VB.Label", "lblgm_" & CStr(i), frmRankStrata)
        With objLabel
            .Caption = "Strata: " & CompareLayers(i).GM
            .Left = 100
            .Top = 1320 + 500 * i
            .width = 3500
            .Visible = True
        End With
     Set objCmb(i) = frmRankStrata.Controls.add("vb.ComboBox", "cboRank" & CStr(i), frmRankStrata)
        With objCmb(i)
            .Visible = True
            .Left = 2500
            .Top = 1320 + 500 * i
            .width = 600
        End With
        For k = 0 To maxlevels - 1
            rank = k + 1
            objCmb(i).AddItem CStr(rank)
        Next k
    If i = maxlevels - 1 Then
    Set objOK = frmRankStrata.Controls.add("vb.CommandButton", "cmdOK", frmRankStrata)
        With objOK
            .Visible = True
            .Left = 2500
            .Top = objCmb(i).Top + 500
            .Caption = "OK"
        End With
    End If
    Next i
End Sub

Private Sub cmdOK_Click()
    Dim k As Integer:    ReDim ctrls(maxlevels)
    ReDim rankLayers(maxlevels):
    
    For k = 0 To maxlevels - 1
        rankLayers(k) = CInt(objCmb(k).SelText)
        Debug.Print (rankLayers(k))
    Next k

This post has been edited by modi123_1: 09 June 2014 - 10:46 AM
Reason for edit:: please use the 'code' button in the editor


Is This A Good Question/Topic? 0
  • +

Page 1 of 1