Visual Basic (17)

1 Name: V.V : 2006-10-20 14:14 ID:jKZjfLf3 This thread was merged from the former /code/ board. You can view the archive here.

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.

2 Name: TT_TT : 2006-10-20 14:16 ID:jKZjfLf3

hey, i can't either. blast it!

3 Name: #!/usr/bin/anonymous : 2006-10-20 16:05 ID:Rjtz4dKs

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

4 Name: #!/usr/bin/anonymous : 2006-10-20 20:24 ID:Heaven

I seem to recall modulo being "Mod" in Visual Basic.

5 Name: #!/usr/bin/anonymous : 2006-10-20 20:39 ID:Heaven

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

6 Name: #!/usr/bin/anonymous : 2006-10-21 21:37 ID:svZlfq/0

>>5
You forgot = 0. If SomeVariable Mod b = 0 Then...

7 Name: #!/usr/bin/anonymous : 2006-10-22 01:05 ID:VkqnPAIo

>>6
IIRC, 0 == false in basic

8 Name: #!/usr/bin/anonymous : 2006-10-22 01:24 ID:Heaven

>>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.

9 Name: #!/usr/bin/anonymous : 2006-10-22 03:33 ID:Heaven

>>8
or you could use Not...

10 Name: #!/usr/bin/anonymous : 2006-10-22 08:18 ID:Heaven

>>9
at which point the line no longer says what it means (even if it does the same thing in effect)

11 Name: #!/usr/bin/anonymous : 2006-10-23 05:31 ID:Heaven

>>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.

12 Name: #!/usr/bin/anonymous : 2006-10-23 05:45 ID:TjNo/9zV

Modulo returns the remainder, not a boolean.

If (Number Mod Test) = 0

13 Name: #!/usr/bin/anonymous : 2006-10-24 00:03 ID:P4tNAkSb

How about If (IsInt){}

14 Name: nobuyuki!GfMr2LTKW. : 2006-12-27 15:39 ID:Heaven

 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

15 Post deleted.

16 Name: #!/usr/bin/anonymous : 2017-01-19 05:42 ID:f+q+80vG

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

17 Name: #!/usr/bin/anonymous : 2017-02-05 10:07 ID:Heaven

It's been 11 years, this thread is old enough to figure it out on its own

Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: