hay guyz, I'm a moron. Inside visual basic (Microsoft visual studio 2005 fyi) is there a way to say if variable a divided by variable b is an integer, execute some code? I know I need an If then statement, but I don't know if any syntax can make sure it's an integer they're using.
hey, i can't either. blast it!
Use the modulo. I don't what it is in Visual Basic, but in most languages it's something like % or mod.
Basically, the modulo operation find the remainder of a division. Of course, if the result is an integer, the remainder is 0.
For instance:
10 % 2 = 0
but
10 % 3 = 1
I seem to recall modulo being "Mod" in Visual Basic.
i've never used visual basic, but i'd guess what you want would look something like this:
If SomeVariable Mod b
' some code goes here
End If
>>5
You forgot = 0
. If SomeVariable Mod b = 0 Then
...
>>7
even if it is (been a while, don't remember off hand), the logic would be backwards -- that block would be executed if the variable is not an integer. it needs the comparison to zero.
>>8
or you could use Not
...
>>9
at which point the line no longer says what it means (even if it does the same thing in effect)
>>7
I'm pretty sure Visual Basic won't accept 1 or 0 as a Boolean type, wanting True or False instead. It's been years though.
Modulo returns the remainder, not a boolean.
If (Number Mod Test) = 0
How about If (IsInt){}
If A / B = math.floor(A / B) then 'do shit
or you can do what everyone else is saying.
If A mod B = 0 then 'it's an integer with no remainder
Been years since I did anything serious in VB but you can probably do something like:
C = A / B
If C = Math.Floor(C) Then
DoSomething()
End If
Though if either A or B is floating point, C may not be exactly 0 even when it should, due to silly rounding errors. To be safe, it might be better to do something like
Epsilon = 0.000001
C = A / B
If (Math.Abs(C - Math.Floor(C)) < Epsilon) Then
DoSomething()
End If
It's been 11 years, this thread is old enough to figure it out on its own