Need a simple, multiple-form-checkbox-counter - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need a simple, multiple-form-checkbox-counter

MJRx9000MJRx9000 Posts: 1Member
[b][red]This message was edited by MJRx9000 at 2004-7-13 1:12:29[/red][/b][hr]
Hi. I'm trying to make a little program with multiple forms under different headings, with several checkboxes on each one; I want to be able to go back and forth through the forms, and the final form will tally up the checkboxes and display the total of each separate form. I've already done the forms, but can someone point me to some code that can handle the tallying?


Comments

  • DjSpiritDjSpirit Posts: 371Member
    : [b][red]This message was edited by MJRx9000 at 2004-7-13 1:12:29[/red][/b][hr]
    : Hi. I'm trying to make a little program with multiple forms under different headings, with several checkboxes on each one; I want to be able to go back and forth through the forms, and the final form will tally up the checkboxes and display the total of each separate form. I've already done the forms, but can someone point me to some code that can handle the tallying?
    :
    [grey]If you for each form add a function returning how many checkboxes are marked. Then you can easily call each forms function, add it all together, you will have your magic number.
    Like this:
    [code]Public Function CountChecks() As integer
    Dim obChk As CheckBox, inCnt As Integer
    For Each obChk In Me.Controls
    If obChk.Value = vbChecked Then inCnt = inCnt + 1
    Next
    CountChecks = inCnt
    End Function
    [/code]

    DjSpirit, you should probably be writing me a lot of checks for this 8)[/grey]
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : Dim obChk As CheckBox, inCnt As Integer

    Unless VB6 or .Net had come up with an intelligent enumerator for the controls collection, that won't work. In VB5 at least, you need to Dim As Control and then do:

    [code]If TypeOf obChk Is CheckBox Then
    If obChk.Value Then inCnt = inCnt + 1
    End If
    [/code]

    Little more than personal preference but if you never use the checkbox's third state (greyed), then I'd rewrite that middle line like this:

    inCnt = inCnt + obChk.Value

    since it's value is 0 if it's unchecked and 1 if it's checked.
Sign In or Register to comment.