Hi,

I'm currently doing a sch proj.

I would like to know how do I add points to the checkboxes and how do I add the checked boxes up to get the overall points?

Below I have an attachment on roughly how I wan it to works in case my words are not that clear.

Pls Help

Best Regards,
Dawn.Lee

Recommended Answers

All 13 Replies

See first: We only give homework help to those who show effort announcement.

I'll give you something to get started with. VB.NET stores controls in controls collections, so you can't have a control array (of checkboxes) like in VB6. Here's an example, how to loop a control collection and check the name property if the control is a checkbox

Dim oCtrl As Control
For Each oCtrl In Me.Controls
  If CType(oCtrl, CheckBox).Name = "GCS" Then

  End If
Next

For storing the points, I would use control's Tag property.

Now you have all the needed clues...

the above code should I instead in the checbox or the label that show the total point or on the form?

Above sample was, how do you get access to your check boxes (Name property) and how you store a value (Tag property) in the check boxes.

Showing the total points is easy

Dim TotalPoints As Integer
.
.
' Calculate total points from checkboxes
.
.
Label1.Text = TotalPoints.ToString

And of course you need to check Checked property too. Forgot that from my last post.

The checkboxs you show are displayed in word document or in vb form?

This is a VB.NET forum. I believe that VBA questions belong to DaniWeb's "Visual Basic 4/5/6" forum.

This is a VB.NET forum. I believe that VBA questions belong to DaniWeb's "Visual Basic 4/5/6" forum.

Sorry? I did not understand what you are trying to say to me?

I would like to know how do I add points to the checkboxes and how do I add the checked boxes up to get the overall points?

Because this is a VB.NET forum, the OP wanted to sum up VB.NET CheckBoxes.

Below I have an attachment on roughly how I wan it to works in case my words are not that clear.

That Word document was just a clarification for the question.

That's what I did mean :)

True but :-/

1- It could be a vb.net automated word document and then he want to count them :)

2- If that is a form and the checkbox is static, why don't he count them manually?

3- your code will work just fine if he you want to count the checkbox in a form dynamically, but I suggest using this single line instead of the IF

For Each _oCtrl As Control In Me.Controls.OfType(Of CheckBox)()
    ' ...
Next

Or he can use LINQ

Dim _ling As IEnumerable(Of CheckBox) = From _CheckBoxes In Me.Controls.OfType(Of CheckBox)() _
                                        Where _CheckBoxes.Checked = False _
                                        Select _CheckBoxes
Debug.Print(_ling.Count)

but I am still not sure what he wants to do.

:?:

2- If that is a form and the checkbox is static, why don't he count them manually?

Manually? You mean if there's a fixed amount of the checkboxes? Then the summing could be done without looping the controls collection. You're right about that. I'm not familiar with GCS, that's why I suggested a "dynamic" solution i.e. the number of the GCS qualities and thus the number of the checkboxes is not fixed.

3- your code will work just fine if he you want to count the checkbox in a form dynamically, but I suggest using this single line instead of the IF

Nice! I wasn't familiar with that syntax :) But CType(_oCtrl, CheckBox) is still needed to get properties of the checkbox control.

Or he can use LINQ

That's a question of the compatibility. I target and test the code with .NET 2.0 and VB.2005. And there's also a lot of user's still using VB.2003. AFAIK LINQ came with .NET 3.5.

1- It could be a vb.net automated word document and then he want to count them :)

;) Well, let's wait for Dawnie's comment and some code.

A quick note

For Each _oCtrl As Control In Me.Controls.OfType(Of CheckBox)()
' ...
Next

I tried to use that syntax with VB.2005. Controls collection does not have OfType method in .NET 2.0. So I (still) suggest using CType(_oCtrl, CheckBox) syntax for the compatibility with pre 3.x versions of .NET.

Controls collection does not have OfType method in .NET 2.0. So I (still) suggest using CType(_oCtrl, CheckBox)

I don't have such experience in diff vb.net versions, I start using vb.net since 6 months only, and I start directly with vb2008

Thank you for your clarification and info, I will keep that in mind in case i need it again.

:)

Hi guy, sorry for the late reply....

I hav did my coding in this way :

Public Class Trial

Private GCS_Value As Integer = 0

Private Sub Trial_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

lblGCSTotal.Text = CStr(GCS_Value)

End Sub

Private Sub cbxEyes4_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

cbxEyes1.Checked = False
cbxEyes2.Checked = False
cbxEyes3.Checked = False
cbxEyes4.Checked = True
update_GCSTotal()

End Sub

Private Sub cbxEyes3_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

.
.
.
.
.
.
.
.


End Sub

Sub update_GCSTotal()
GCS_Value = 0
Dim oCtrl As Control

For Each oCtrl In tblEyes.Controls
Try
If CType(oCtrl, CheckBox).Name.Contains("Eyes") And CType(oCtrl, CheckBox).Checked Then
GCS_Value += CInt(oCtrl.Text)
End If
Catch ex As Exception

End Try

Next

For Each oCtrl In tblVerbal.Controls
Try
If CType(oCtrl, CheckBox).Name.Contains("Verbal") And CType(oCtrl, CheckBox).Checked Then
GCS_Value += CInt(oCtrl.Text)
End If
Catch ex As Exception

End Try

Next

For Each oCtrl In tblMotor.Controls
Try
If CType(oCtrl, CheckBox).Name.Contains("Motor") And CType(oCtrl, CheckBox).Checked Then
GCS_Value += CInt(oCtrl.Text)
End If
Catch ex As Exception

End Try

Next

lblGCSTotal.Text = CStr(GCS_Value)

End Sub
End Class

Now I hav problem to putting it to working in tab instead of on forms itself.

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.