英文:
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 < 8 Then
If TextBox4.Value = "" Then err = 1
If TextBox5.Value = "" Then err = 1
If TextBox6.Value = "" Then err = 1
If IsNumeric(TextBox5.Value) = False Then err = 4
If IsNumeric(TextBox6.Value) = False Then err = 4
If TextBox6.Value > TextBox5.Value Then err = 2
If err = 1 Then MsgBox "Incomplete Item Data!"
If err = 2 Then
MsgBox "Delivered quantity cannot be more than PO quantity!"
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
End If
'MsgBox delv & " is greater than " & po
If err = 4 Then MsgBox "Quantity value(s) incorrect!"
If err = 0 Then
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
End If
Else
MsgBox "Sorry! You cannot add more than 7 items in single delivery note!" & vbNewLine & "Create another delivery note for remaining items."
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) > CDbl(TextBox5.Value) Then err = 2
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论