积极答复者
想请帮忙看看我的代码auto count 的代码少了什么

问题
-
我篇写了有关textbox auto count 的代码。我遇到的问题是我所count的数字会出现问题。恳请帮忙指点以下代码谢谢
当user 在textbox1 打任何数字时total.text 会出现user打的任何数字当user cancel 或delete任何数字时total.text都会同步跟textbox1的答案一样。
Dim S1, S2, S3, S4, S5, S6, S7, S8 As Double
Private Sub txtsg1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsg1.TextChanged
If txtsg1.Text = "" Then
txtsg1.Focus()
txtsg1.SelectAll()
Else
Try
S1 = CDbl(CStr(txtsg1.Text))
Catch ex As Exception
MsgBox("Pls fill correct number")
txtsg1.Text = ""
End Try
End If
Total.Text = CStr(Val(S1) + Val(S2) + Val(S3) + Val(S4) + Val(S5) + Val(S6) + Val(S7) + Val(S8))
End Sub- 已编辑 christing 2020年5月29日 3:19
答案
-
Hi christing,
>>当user 在textbox1 打任何数字时total.text 会出现user打的任何数字当user cancel 或delete任何数字时total.text都会同步跟textbox1的答案一样。
如果要同步第二个 textbox 'total' 的 text 属性和 第一个 'txtsg1' 一样, 你可以参考以下代码:
Private Sub txtsg1_TextChanged(sender As Object, e As EventArgs) Handles txtsg1.TextChanged If txtsg1.Text = "" Then txtsg1.Focus() txtsg1.SelectAll() Else Try S1 = CDbl(CStr(txtsg1.Text)) Catch ex As Exception MsgBox("Pls fill correct number") txtsg1.Text = "" End Try End If If Not Total.Focused AndAlso txtsg1.Text <> Total.Text Then Total.Text = txtsg1.Text End If End Sub
测试结果:
另外我注意到你定义了 8个double属性的变量,并在代码里相加,如果以上代码不能解决问题,请提供关于该问题更多的细节。
Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已编辑 Xingyu ZhaoMicrosoft contingent staff, Moderator 2020年5月29日 7:22
- 已标记为答案 christing 2020年5月29日 12:28
全部回复
-
Hi christing,
>>当user 在textbox1 打任何数字时total.text 会出现user打的任何数字当user cancel 或delete任何数字时total.text都会同步跟textbox1的答案一样。
如果要同步第二个 textbox 'total' 的 text 属性和 第一个 'txtsg1' 一样, 你可以参考以下代码:
Private Sub txtsg1_TextChanged(sender As Object, e As EventArgs) Handles txtsg1.TextChanged If txtsg1.Text = "" Then txtsg1.Focus() txtsg1.SelectAll() Else Try S1 = CDbl(CStr(txtsg1.Text)) Catch ex As Exception MsgBox("Pls fill correct number") txtsg1.Text = "" End Try End If If Not Total.Focused AndAlso txtsg1.Text <> Total.Text Then Total.Text = txtsg1.Text End If End Sub
测试结果:
另外我注意到你定义了 8个double属性的变量,并在代码里相加,如果以上代码不能解决问题,请提供关于该问题更多的细节。
Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已编辑 Xingyu ZhaoMicrosoft contingent staff, Moderator 2020年5月29日 7:22
- 已标记为答案 christing 2020年5月29日 12:28
-
@XING YU ZHAO
感谢你回答的问题
我有textbox1 和textbox 2
我想呈现的是当user在textbox1 打数字时total textbox可以马上读到textbox1的资料,当user在textbook2 打字的时候也能同步将资料呈现在total textbox (如果texbox1有资料total textbox 就会将textbox1 和textbox2 的数字加在一起)
如下图
我遇到的问题是
当user将textbox2的数字删除后total的数字还是保持不变是2.我想呈现的是当user将textbox2 的数字删除后total textbox 会自动算并且将total textbox 变成1.