Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In my application I have 4 rows, and each row contains 1 checkbox and 3 textboxes. What I’m trying to do is to add the value of first checked row (for each column separately) with other checked rows. Then count how many boxes were checked and divided the sum by that amount (average)

Row1 --- |    cb1=__checked    |    tb01=12    |    tb02=3   |    tb03=4.25    | 
Row2 --- |    cb2=__checked    |    tb04=14    |    tb05=5   |    tb06=1.75    | 
Row3 --- |    cb3=unchecked   |    tb07=19    |    tb08=9   |    tb09=1.25    | 
Row4 --- |    cb4=__checked   |    tb10=24    |    tb11=1   |    tb12=3.50    | 
__________________________________________________________________
Button1  |       tb13=3       |    tb14=50    |    tb15=9   |    tb16=9.50    |
__________________(tb14 / tb13)__________________________________


Now I want to divide only first column result (tb14) by the amount of checked boxes (tb13) so the results I’m looking for are;

1st column: tb14 / tb13 = 16.67
2nd column: tb15 = 9
3rd column: tb16 = 9.50

I’m newbie and I have been scratching my head hard for last few days …and nights
Thank you in advance for any help you can provide.

I don’t know if that’s the way to start with…
That’s just for a first column!

VB.NET
Dim col1 As String

Dim tb01, tb04, tb07, tb10 As Decimal

Tb01 = TextBox01.Text
Tb03 = TextBox04.Text
Tb07 = TextBox07.Text
Tb10 = TextBox10.Text

If CheckBox1.Checked Then
    col1 = col1 & tb01
End If

If CheckBox2.Checked Then
    col1 = col1 & tb04
End If

If CheckBox3.Checked Then
    col1 = col1 & tb07
End If

If CheckBox4.Checked Then
    col1 = col1 & tb10
End If

‘…and just for testing to see my results…

MessageBox.Show(col1)


they are; (121424) 12, 14 and 24

I’m stock here
Posted
Updated 2-Aug-16 15:27pm
v4
Comments
Maciej Los 2-Aug-16 16:10pm    
Seems, i have seen this before...
Jack-tek460 2-Aug-16 17:36pm    
Ok, went little bit further.

Now I have all results I need and the only question left is how to get the number of checked boxes? (from my example above the number is “3”)

C#
Dim col1 As String
 
Dim tb01, tb04, tb07, tb10 As Decimal
 
Tb01 = Val(TextBox01.Text)
Tb03 = Val(TextBox04.Text)
Tb07 = Val(TextBox07.Text)
Tb10 = Val(TextBox10.Text)
 
If CheckBox1.Checked Then
    col1 = col1 & tb01
End If
 
If CheckBox2.Checked Then
    col1 = col1 & tb04
End If
 
If CheckBox3.Checked Then
    col1 = col1 & tb07
End If
 
If CheckBox4.Checked Then
    col1 = col1 & tb10
End If

Dim col1row1 As String = col1 & tb01
Dim col1row2 As String = col1 & tb04
Dim col1row3 As String = col1 & tb07
Dim col1row4 As String = col1 & tb10
        
‘…and just for testing to see my results…
 
MessageBox.Show(col1row1)
MessageBox.Show(col1row2)
MessageBox.Show(col1row3)
MessageBox.Show(col1row4)
 
Share this answer
 
v2
Comments
Jack-tek460 2-Aug-16 20:18pm    
I have figured it out! This code might not look “right” for advanced programmers but it works for me and I hope it helps someone.

I will update new code in few… I have to change the names of my program’s text boxes, check boxes and few other things to what I posted here.
C#
Dim col1 As Long
 
Dim tb01, tb04, tb07, tb10 As Decimal
 
Tb01 = Val(TextBox01.Text)
Tb03 = Val(TextBox04.Text)
Tb07 = Val(TextBox07.Text)
Tb10 = Val(TextBox10.Text)
 
Dim checked01 As Decimal
Dim checked04 As Decimal
Dim checked07 As Decimal
Dim checked10 As Decimal

If CheckBox1.Checked Then
    Checked01 = 1
    col1 = col1 & tb01
ElseIf CheckBox1.Checked = False Then
    Checked01 = 0
End If

If CheckBox2.Checked Then
    Checked04 = 1
    col1 = col1 & tb04
ElseIf CheckBox2.Checked = False Then
    Checked04 = 0
End If

If CheckBox3.Checked Then
    Checked07 = 1
    col1 = col1 & tb07
ElseIf CheckBox3.Checked = False Then
    Checked07 = 0
End If 

If CheckBox4.Checked Then
    Checked10 = 1
    col1 = col1 & tb10
ElseIf CheckBox4.Checked = False Then
    Checked10 = 0
End If 

Dim checkedcol1_01 As Decimal = checked01
Dim checkedcol1_04 As Decimal = checked04
Dim checkedcol1_07 As Decimal = checked07
Dim checkedcol1_10 As Decimal = checked10

Dim checkedsum As Decimal = Val(checkedcol1_01 + checkedcol1_04 + checkedcol1_07 + checkedcol1_10)


MessageBox.Show (checkedsum & " boxes were checked! ...just for my reference")


Dim col1row1 As Decimal
Dim col1row2 As Decimal
Dim col1row3 As Decimal
Dim col1row4 As Decimal

If CheckBox1.Checked Then
    col1row1 = (col1 And tb01) - col1 + tb01
ElseIf CheckBox1.Checked = False Then
    col1row1 = 0
End If

If CheckBox2.Checked Then
    col1row2 = (col1 And tb04) - col1 + tb04
ElseIf CheckBox2.Checked = False Then
    col1row2 = 0
End If

If CheckBox3.Checked Then
    col1row3 = (col1 And tb07) - col1 + tb07
ElseIf CheckBox3.Checked = False Then
    col1row3 = 0
End If

If CheckBox4.Checked Then
    col1row4 = (col1 And tb10) - col1 + tb10
ElseIf CheckBox4.Checked = False Then
    col1row4 = 0
End If

If CheckBox1.CheckState = CheckState.Unchecked And CheckBox2.CheckState = CheckState.Unchecked And CheckBox3.CheckState = CheckState.Unchecked And CheckBox4.CheckState = CheckState.Unchecked Then
    MsgBox("Please select at least one check box!", vbExclamation, "Error!")
    Exit Sub
End If
        
Dim finalResults_col1 As Decimal = Val(col1row1 + col1row2 + col1row3 + col1row4) / checkedsum


MessageBox.Show(finalResults_col1 & " is a final value for column 1")
 
Share this answer
 
v3

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