简体   繁体   English

在visual basic中计算程序

[英]calculating program in visual basic

I trying to make program in visual basic in Text Changed event that when enter value the text box the program will store that value and when delete that value and enter new value it will use the first value and Compares with the new value if the new value > from the first value Decreases the new value from the first value (new value-first value) and if the new value < from the first value it will Decreases the first value from new value (first value - new value) and the The result another text box 我试图在Text Changed事件中使用visual basic程序,当输入值时,程序将存储该值的文本框,当删除该值并输入新值时,它将使用第一个值并与新值比较新值>从第一个值减去第一个值的新值(新值 - 第一个值),如果新值<从第一个值开始,它将从新值减去第一个值(第一个值 - 新值)和结果另一个文本框

Dim f As String
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    If TextBox2.Text > f Then
        TextBox18.Text = TextBox2.Text - f
        f = (TextBox2.Text)
    End If

I make this code it work but when the new value is (10) or Larger its not working 我使这个代码工作但是当新值为(10)或更大时它不起作用

Try the following: 请尝试以下方法:

Dim f As String
Private Sub TextBox2_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.Leave
If not string.isnullOrEmpty(TextBox2.Text) Then
If CDbl(TextBox2.Text) > CDbl(f) Then
    TextBox18.Text = CStr(CDbl(TextBox2.Text) - CDbl(f))
    f = TextBox2.Text
End If
End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM