这里是我在VB.NET中进行编码的地方,我正在设计一些FEESMODULE,在其中输入TEXTBOX的值,例如PROSPACTUS,REGISTRATION,TUTION和EXAM,并希望在输入这些值时时间值也应一起添加到名为TOTAL的TEXTBOX中。我尝试过以下代码,但答案却不正确
print(r['d']['BidTotalVolume'])
答案 0 :(得分:0)
将其放在表单加载事件的末尾。您将必须调整组名,和/或将其他组包括在例程中。这不是解决方案的问题,但我认为您应该可以轻松推断出您的解决方案。您确实应该使用数字类型控件,例如NumericUpDown。
'Use the parent control collection to add handles
For Each TxBx As TextBox In GroupBox1.Controls.OfType(Of TextBox)
AddHandler TxBx.KeyDown, Sub(s As TextBox, ex As KeyEventArgs)
'at least limit to numeric keys, include backspace,selete and minus
Dim AllowedKeys() As Integer = {49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
189, 97, 98, 99, 100, 101, 102, 103, 104, 105, 96, 109, 8, 46}
If Not AllowedKeys.Contains(ex.KeyData) Then
ex.SuppressKeyPress = True
End If
End Sub
AddHandler TxBx.KeyUp, Sub(s As TextBox, ex As KeyEventArgs)
'Sum your madness
Dim Tot As Integer = 0
For Each Tb As TextBox In GroupBox1.Controls.OfType(Of TextBox)
Dim ChkInt As Integer
Integer.TryParse(Tb.Text, ChkInt)
Tot += ChkInt
Next
TxBxTotal.Text = Tot.ToString
End Sub
Next
答案 1 :(得分:-1)
目前还不清楚您要做什么。我猜它每当其他人获得新值时都会更新TextBox8。试试这个:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged,TextBox3.TextChanged, TextBox4.TextChanged
TextBox8.Text = SumValues()
'Label12.Text = a - Integer.Parse(TextBox1.Text)
End Sub
Private Function SumValues() As Integer
Dim Total As Integer = 0
Total += IIf(String.IsNullOrEmpty(TextBox1.Text), 0, Val(TextBox1.Text)) + _
IIf(String.IsNullOrEmpty(TextBox2.Text), 0, Val(TextBox2.Text)) + _
IIf(String.IsNullOrEmpty(TextBox3.Text), 0, Val(TextBox3.Text)) + _
IIf(String.IsNullOrEmpty(TextBox4.Text), 0, Val(TextBox4.Text))
Return Total
有更有效的方法来做到这一点,哈哈,但这就是我要做的。简单明了。