Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following code in "vb.net 2008" I've written.
//*********************************************
VB
Module Module1
    Sub Main()
        Dim number3 As Double
        Dim number1, number2 As Integer
        On Error GoTo error1
        number1 = 10
        number2 = 0
        number3 = number1 / number2
        Console.Write(number3)
        Console.ReadLine()
        Exit Sub
error1:
        Console.Write("Exist one Error")
        Console.ReadLine()
    End Sub
End Module

//************************************************
Code gives me wrong result.(Results displayed wrong-->"infinity")
If it must be "Exist one Error"
help me ?
Posted

Probably the compiler is converting number1 and/or number2 to Double, since result goes to Double. Since double/single values are not integers, and are not precise - the value 0 actually may be 0.00000000484 - and making the division possible!

Try putting the value into some integer variable.
 
Share this answer
 
Double can store +Infinity and -Infinity as well while an Integer cannot. In your case you are trying to store Infinity in a Double value which is perfectly valid and that's why your answer is Infinity. If number3 is an Integer then it will print "Exist one Error".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900