大于运算符对某些数字为什么无法正常工作?

huangapple go评论63阅读模式
英文:

Why is the greater than operator is not working properly for some numbers?

问题

以下是您代码的翻译部分:

私有子 CommandButton2_Click()

Dim err As Integer
err = 0

如果 clickcount < 8 Then
    如果 TextBox4.Value = "" 然后 err = 1
    如果 TextBox5.Value = "" 然后 err = 1
    如果 TextBox6.Value = "" 然后 err = 1
    如果 IsNumeric(TextBox5.Value) = False 然后 err = 4
    如果 IsNumeric(TextBox6.Value) = False 然后 err = 4
    如果 TextBox6.Value > TextBox5.Value 然后 err = 2
    
    如果 err = 1 然后 MsgBox "不完整的项目数据!"
    如果 err = 2 然后
        MsgBox "交付数量不能超过PO数量!"
        TextBox5.Value = ""
        TextBox6.Value = ""
        TextBox7.Value = ""
    结束 如果
    'MsgBox delv & " is greater than " & po
    如果 err = 4 然后 MsgBox "数量值不正确!"
    如果 err = 0 然后
        DeliveryNote.ListBox1.ColumnCount = 5
        DeliveryNote.ListBox1.ColumnWidths = "20,120,55,50,30"
        DeliveryNote.ListBox1.AddItem
        
        ListBox1.AddItem
        ListBox1.List(clickcount - 1, 0) = clickcount
        ListBox1.List(clickcount - 1, 1) = TextBox4.Value
        ListBox1.List(clickcount - 1, 2) = TextBox5.Value
        ListBox1.List(clickcount - 1, 3) = TextBox6.Value
        ListBox1.List(clickcount - 1, 4) = TextBox5.Value - TextBox6.Value
        TextBox4.Value = ""
        TextBox5.Value = ""
        TextBox6.Value = ""
        TextBox7.Value = ""
        
        clickcount = clickcount + 1
    结束 如果
其他

MsgBox "抱歉!您不能在单个交货通知中添加超过7个项目!" & vbNewLine & "为剩余项目创建另一个交货通知。"

结束 如果

结束 子

请注意,这是您代码的翻译,不包括错误和接受的值的部分。如果您有任何其他问题或需要进一步的帮助,请随时提出。

英文:
Private Sub CommandButton2_Click()

Dim err As Integer
err = 0

If clickcount &lt; 8 Then
    If TextBox4.Value = &quot;&quot; Then err = 1
    If TextBox5.Value = &quot;&quot; Then err = 1
    If TextBox6.Value = &quot;&quot; Then err = 1
    If IsNumeric(TextBox5.Value) = False Then err = 4
    If IsNumeric(TextBox6.Value) = False Then err = 4
    If TextBox6.Value &gt; TextBox5.Value Then err = 2
    
    If err = 1 Then MsgBox &quot;Incomplete Item Data!&quot;
    If err = 2 Then
        MsgBox &quot;Delivered quantity cannot be more than PO quantity!&quot;
        TextBox5.Value = &quot;&quot;
        TextBox6.Value = &quot;&quot;
        TextBox7.Value = &quot;&quot;
    End If
    &#39;MsgBox delv &amp; &quot; is greater than &quot; &amp; po
    If err = 4 Then MsgBox &quot;Quantity value(s) incorrect!&quot;
    If err = 0 Then
        DeliveryNote.ListBox1.ColumnCount = 5
        DeliveryNote.ListBox1.ColumnWidths = &quot;20,120,55,50,30&quot;
        DeliveryNote.ListBox1.AddItem
        
        ListBox1.AddItem
        ListBox1.List(clickcount - 1, 0) = clickcount
        ListBox1.List(clickcount - 1, 1) = TextBox4.Value
        ListBox1.List(clickcount - 1, 2) = TextBox5.Value
        ListBox1.List(clickcount - 1, 3) = TextBox6.Value
        ListBox1.List(clickcount - 1, 4) = TextBox5.Value - TextBox6.Value
        TextBox4.Value = &quot;&quot;
        TextBox5.Value = &quot;&quot;
        TextBox6.Value = &quot;&quot;
        TextBox7.Value = &quot;&quot;
        
        clickcount = clickcount + 1
    End If
Else

MsgBox &quot;Sorry! You cannot add more than 7 items in single delivery note!&quot; &amp; vbNewLine &amp; &quot;Create another delivery note for remaining items.&quot;

End If

End Sub

Error

大于运算符对某些数字为什么无法正常工作?

Accepted Values

大于运算符对某些数字为什么无法正常工作?

I have attached the values resulting in error as well as the values that got processed without error. I want the the condition to always work and not give these kind of errors.

答案1

得分: 0

尝试在执行比较之前将文本转换为数字。现在,它可能只是比较字符串。

尝试使用这个(未经测试)...

如果 CDbl(TextBox6.Value) > CDbl(TextBox5.Value) Then err = 2

英文:

Maybe try and cast your text to a number before performing the comparison. Right now, it's probably just comparing strings.

Try this instead (untested) ...

If CDbl(TextBox6.Value) &gt; CDbl(TextBox5.Value) Then err = 2

huangapple
  • 本文由 发表于 2023年7月18日 14:47:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定