Hi all, I have a userform which is being built as a calulation tool
I have a combo boxes and text boxes that are dependant on each other, once filled in there is a button that should calculate a range of values dependant on
1.) The value in the text box
2.) The selection in the corresponding combo box
There are 36 of each type in total
I have been looking at a number of potential methods including arrays and loops but a collection seems to be the only one that looks like it may work, only trouble is I can't get my head around how to set it up using the examples I've seen so far online.
I could write it out as below, but it would be a nightmare should I need to change anything etc
If I could add all these combo boxes and text boxes to a collection, then I should be able to loop through them instead of having to type out the 'Call chkAtt()' for each combo box, assuming this is correct I just need to know how to
1.)Create said collection(s)?
2.)Add the objects
3.)How to loop through the items and update the label with the total (I could work this out myself I'm sure but it's Friday afternoon and my head is sore after trying to understand collections all day -_-)
If more info required please ask, I don't always explain specifics very well ><
(or if it can be done another way I'm open to that too!)
Thanks in advance
I have a combo boxes and text boxes that are dependant on each other, once filled in there is a button that should calculate a range of values dependant on
1.) The value in the text box
2.) The selection in the corresponding combo box
There are 36 of each type in total
I have been looking at a number of potential methods including arrays and loops but a collection seems to be the only one that looks like it may work, only trouble is I can't get my head around how to set it up using the examples I've seen so far online.
I could write it out as below, but it would be a nightmare should I need to change anything etc
Code:
Private Sub cbAdd_Click()
With lbHP 'label name where total will be displayed
lbHP.Caption = 0 'set label value to 0
Call chkAtt(lbHP, cbS1MA, tbS1MA, "HP") 'Call function to check if the attribute in each combo box
Call chkAtt(lbHP, cbS2MA, tbS2MA, "HP") 'matches the label type, and if so add the value of the corresponding
Call chkAtt(lbHP, cbS3MA, tbS3MA, "HP") 'text box
Call chkAtt(lbHP, cbS4MA, tbS4MA, "HP")
Call chkAtt(lbHP, cbS5MA, tbS5MA, "HP")
Call chkAtt(lbHP, cbS6MA, tbS6MA, "HP")
End With
End Sub
Function chkAtt(ByVal myLB As Object, myCB As Object, myTB As Object, myTest As String)
If myCB = myTest Then
myLB.Caption = CLng(myLB.Caption) + CLng(myTB)
Else
End If
End Function
If I could add all these combo boxes and text boxes to a collection, then I should be able to loop through them instead of having to type out the 'Call chkAtt()' for each combo box, assuming this is correct I just need to know how to
1.)Create said collection(s)?
2.)Add the objects
3.)How to loop through the items and update the label with the total (I could work this out myself I'm sure but it's Friday afternoon and my head is sore after trying to understand collections all day -_-)
If more info required please ask, I don't always explain specifics very well ><
(or if it can be done another way I'm open to that too!)
Thanks in advance