Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the code in question:

VB
Friend Sub cbxSelRun_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxSelRun.SelectedIndexChanged
    Dim tmpBtn As Object = "System.Windows.Forms.Button"
    For i = 1 To 6
        If Dir(a_RunFldr(cbxSelRun.SelectedIndex.ToString + 1) & "\Libraries\" & a_RTLib(i), vbDirectory) <> "" Then
            s_Temp = LSet(a_RTLib(i), 4)
            tmpBtn = "btn" & s_Temp
            tmpBtn.enabled = True
        End If
    Next i
End Sub


It's not working {probably obvious}. What I have are 6 buttons. They start off disabled and should only be enabled if the target Folder is present. I could do this with lengthy code, but I'd prefer to just use the For...Next loop to (1) Check for the folder THEN (2) Enable the appropriate button.

These are the regular variables:
VB
a_RTLib(1) = "Character"
a_RTLib(2) = "Face"
a_RTLib(3) = "Hair"
a_RTLib(4) = "Hand"
a_RTLib(5) = "Pose"
a_RTLib(6) = "Props"


And the button names:
VB
btnChar
btnFace
btnHair
btnHand
btnPose
btnProp


If I need to change the button names to numbers that would be fine, so long as I can get them to enable/disable using variables when I need to.

Any help would be appreciated!

Peace to you and yours,
Matthew "Dra'Gon" Stohler
Posted

1 solution

You may use, for instance a Dictionary: declare
a variable like
VB
Dim dic As New Dictionary(Of String, Button)


then initialize it:

VB
dic.Add("Character", btnChar)
dic.Add("Face", btnFace)
' and so on...


Then you may access each Button using the corrensponding String, for instance

VB
dic("Character").Enabled = True
 
Share this answer
 
Comments
BlueDragonFire 11-Jul-11 16:33pm    
You, Sir, are my hero! Works like a charm!!!!

Many, MANY thanks!!!

Peace to you and yours,
Matthew "Dra'Gon" Stohler
CPallini 11-Jul-11 16:43pm    
You are welcome :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900