Private Sub cmdSimulate_Click()
Dim comm As CommandButton
Dim zi As Long, ki As Long
Dim shorts(10) As Integer, count As Integer
Dim temps As Integer, z As Integer, n As Integer, m As Integer, i As Integer


If typeSched = 1 Then
temps = 0

btnP(0).Width = Val(txtBT(0).Text) * 100

    For ki = 1 To numPro
    Load btnP(ki)
    With btnP(ki)
    btnP(ki).Height = 375
    btnP(ki).Width = Val(txtBT(ki - 1).Text) * 100
    btnP(ki).Left = btnP(ki - 1).Left + btnP(ki - 1).Width
    btnP(ki).Visible = True
    btnP(ki).Caption = "P" & ki
    End With
    Next

ElseIf typeSched = 2 Then

    temps = 0
    i = 0
    For n = 0 To numPro - 1
    shorts(n) = Val(txtBT(n).Text)
    Next

    For y = 0 To 9 
         For x = y + 1 To UBound(shorts) - 1
            If shorts(y) > shorts(x) Then
                temps = shorts(y)
                shorts(y) = shorts(x)
                shorts(x) = temps
            End If
         Next x
    Next y


    btnP(0).Width = shorts(0) * 100

    For ki = 1 To 10
        Load btnP(ki)
        With btnP(ki)
        btnP(ki).Height = 375
        btnP(ki).Width = shorts(ki - 1) * 100
        btnP(ki).Left = btnP(ki - 1).Left + btnP(ki - 1).Width

        btnP(ki).Visible = True
        btnP(ki).Caption = "P" & turn(ki - 1)
        End With
    Next


ElseIf typeSched = 3 Then

    temps = 0

    For i = 0 To numPro - 1
    shorts(i) = Val(txtPN(i).Text)
    Next

    For y = 0 To 9 
         For x = y + 1 To UBound(shorts) - 1
            If shorts(y) > shorts(x) Then
                temps = shorts(y)
                shorts(y) = shorts(x)
                shorts(x) = temps
            End If
         Next x
    Next y


    btnP(0).Width = shorts(0) * 100

    For ki = 1 To 10
        Load btnP(ki)
        With btnP(ki)
        btnP(ki).Height = 375
        btnP(ki).Width = rep(ki - 1) * 100
        btnP(ki).Left = btnP(ki - 1).Left + btnP(ki - 1).Width
        btnP(ki).Caption = "P" & turn(ki - 1)
        btnP(ki).Visible = True
        End With
    Next


ElseIf typeSched = 4 Then

End If
End Sub

hello daniweb folks. i am in need of help. My codes here works fine (or so i thought). But whenever i click again this command to show another array of commandbuttons in different sequence, the "error: Object already loaded". what should i do? would somebody be kind enough to guide this ignorant me? Thank you, Daniweb folks. :)

well, i have figured it out now.. XD

If btnP.UBound > 0 Then
        For ki = 1 To btnP.UBound
            Unload btnP(ki)
        Next ki
End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.