错误的goto吗? [英] on error goto?

查看:115
本文介绍了错误的goto吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我编写的"vb.net 2008"中的代码.
//*********************************************

Following code in "vb.net 2008" I''ve written.
//*********************************************

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


//****************************************************
代码给我错误的结果.(结果显示错误->"infinity")
如果必须为存在一个错误"


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

推荐答案

可能是编译器正在将number1和/或number2转换为Double,因为结果将转换为Double.由于double/single值不是整数,也不精确-值0实际上可能是0.00000000484-并使除法成为可能!

尝试将值放入一些整数变量中.
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.


Double可以存储+ Infinity和-Infinity,而Integer则不能.在您的情况下,您尝试将Infinity存储在完全有效的Double值中,这就是为什么您的答案是Infinity的原因.如果number3是一个整数,则它将显示存在一个错误".
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".


这篇关于错误的goto吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆