问题描述
在我的应用程序中,我有4行,每行包含1个复选框和3个文本框。我要做的是将第一个检查行的值(对于每个列分别)添加到其他已检查的行。然后计算检查了多少个盒子并将总和除以该数量(平均值)
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)__________________________________
现在我想只将第一列结果(tb14)除以复选框(tb13)所以我正在寻找的结果是;
第1栏:tb14 / tb13 = 16.67
第2栏: tb15 = 9
第3栏:tb16 = 9.50
我是新手,过去几天我一直在努力...和晚上
提前感谢您提供任何帮助。
我不知道这是否是开始的方式......
这只是第一列!
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!
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)
他们是; ( 121424
) 12
, 14
和 24
我在这里库存
they are; (121424
) 12
, 14
and 24
I’m stock here
推荐答案
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)
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")
这篇关于Vb总和检查了4行的文本框,并将它们除以检查的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!