I have a need to do conditional rounding. I need to check to see if a variable is an integer. If it is, do nothing BUT if it's not, round down to the next whole number. How can I check to see if a variable is an integer? Thanks, Jeremy
Printable View
I have a need to do conditional rounding. I need to check to see if a variable is an integer. If it is, do nothing BUT if it's not, round down to the next whole number. How can I check to see if a variable is an integer? Thanks, Jeremy
Use the Int() function, i.e.VB Code:
Var = Int(Var)
Quote:
Originally posted by JCScoobyRS
How can I check to see if a variable is an integer?
VB Code:
If Var = Int(Var) Then MsgBox "It Is" Else MsgBox "It Isn't" End If
Note that what Aaron is getting at doesn't actually check whether the number is an integer or not, it just converts it to one. If you only want to round DOWN in every case (11.9 goes to 11), then this, or n\1 (integer divide by one) will work. If you want to do more than just round the value and end up with an integer, then manovo11 has got a better solution.
So this:
VB Code:
PPS = 1 / ItemRec!PS_QTY_P PPS = Int(PPS)
where PPS = 17.125 doesn't round down to 17? How would I modify this to do that? Thanks, Jeremy
VB Code:
PPS = Int(PPS)
If you do
and then doVB Code:
PPS = 17.125
what is PPS set to at the end? Is it returning 17, or 18, or what? What type of variable do you have PPS dimmed as?VB Code:
PPS = Int(PPS)
Here is the code:
VB Code:
Private Sub Get_MHPricing(ByVal lngVvIndex As Long) 'Get Pricing for Hardware/Materials If ItemRec2!IM_PROD_CODE = "M" Then Dim PPS As Double Dim SC As Long If ItemRec!PS_QTY_P = 0 Then PPS = 1 Else PPS = 1 / ItemRec!PS_QTY_P PPS = Int(PPS) End If If txtQuantity(lngVvIndex).Text < PPS Then SC = 1 Else SC = CLng(((txtQuantity(lngVvIndex).Text + 2) / PPS) + 0.49) End If txtMaterial(lngVvIndex).Text = txtMaterial(lngVvIndex).Text + ((SC * ItemRec2!IM_COST) / txtQuantity(lngVvIndex).Text) ElseIf ItemRec2!IM_PROD_CODE = "H" Then Dim QPQ As Single QPQ = ItemRec!PS_QTY_P * txtQuantity(lngVvIndex).Text If ItemRec2!IM_J_QTY1 = 0 Then txtHardware(lngVvIndex).Text = ItemRec!PS_QTY_P * ItemRec2!IM_COST Else If QPQ < ItemRec2!IM_J_QTY1 Then txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_COST) ElseIf QPQ >= ItemRec2!IM_J_QTY1 And QPQ < ItemRec2!IM_J_QTY2 Then txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES1) ElseIf QPQ >= ItemRec2!IM_J_QTY2 And QPQ < ItemRec2!IM_J_QTY3 Then txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES2) ElseIf QPQ >= ItemRec2!IM_J_QTY3 And QPQ < ItemRec2!IM_J_QTY4 Then txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES3) ElseIf QPQ >= ItemRec2!IM_J_QTY4 And QPQ < ItemRec2!IM_J_QTY5 Then txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES4) ElseIf QPQ >= ItemRec2!IM_J_QTY5 Then txtHardware(lngVvIndex).Text = txtHardware(lngVvIndex).Text + (ItemRec!PS_QTY_P * ItemRec2!IM_PRICES5) End If End If End If End Sub
Thanks, Jeremy