Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.