Click here to Skip to main content
15,921,884 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
Dave Kreskowiak23-Aug-05 2:13
mveDave Kreskowiak23-Aug-05 2:13 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
Christian Graus23-Aug-05 13:23
protectorChristian Graus23-Aug-05 13:23 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
progload21-Aug-05 19:03
progload21-Aug-05 19:03 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
Christian Graus21-Aug-05 19:16
protectorChristian Graus21-Aug-05 19:16 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
progload21-Aug-05 21:06
progload21-Aug-05 21:06 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
Christian Graus22-Aug-05 11:43
protectorChristian Graus22-Aug-05 11:43 
AnswerRe: VBer new to VB.net - handles divide by zero? Pin
Daniel132418-Aug-05 16:15
Daniel132418-Aug-05 16:15 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
Christian Graus18-Aug-05 17:09
protectorChristian Graus18-Aug-05 17:09 
Daniel1324 wrote:
If you cast n1 / n2 to an integer...
lblOut.Text = CInt(n1 / n2)
It will throw a divide by zero exception


So the problem is with the Single object ? C# behaves differently in this case though, with the same object. It still threw an exception, as it should.

Daniel1324 wrote:
Not sure why that is, but setting a labels text returns 'Infinity'.

Because in VB.NET, an int divided by 0 = infinity when passed to a Single. I don't know why, or why this conversion is obviously implicit. It's the stupidest thing I've ever seen. Like I said, everyone here is still laughing about it.

Here's more fun. If you make n3 an Integer instead of a Single, this code will throw what exception ?

Dim n1, n2 As Integer
Dim n3 As Integer
Dim s As String
n1 = CInt("5")
n2 = CInt("0")
Try
n3 = n1 / n2
s = n3
Catch ex As Exception
s = "Warning!"
End Try

The answer is NOT the 'DivideByZeroException', but an 'OverflowException'. Oh yeah, VB.NET is a real programming language...

Daniel1324 wrote:
Dont forget, despite the huge, widespread use of VB, its not a real programming language.

VB is widely used because it was designed for people who can't program to be able to knock something out. For that, it works. What percentage of applications you bought and run on your desktop were written in VB ?

Daniel1324 wrote:
You cant write halfway decent programs with VB.net because it sucks so much.

Yes, you can write a decent program in VB. Hell, you can write a decent program in almost any language. But that doesn't make it a good tool for the job. On the other end of the coin, you can write any program you like in C. But why would you want to ? C is at least useful, but like VB, it has a lot of hidden traps for the unwary traveller. And that would be my main point. A language for beginners that is rife with hidden gotchas, unexplainable syntax and inexcusable behavour ? Give me a break.


Christian Graus - Microsoft MVP - C++
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
Daniel132418-Aug-05 17:25
Daniel132418-Aug-05 17:25 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
Christian Graus18-Aug-05 17:32
protectorChristian Graus18-Aug-05 17:32 
AnswerRe: VBer new to VB.net - handles divide by zero? Pin
progload18-Aug-05 19:38
progload18-Aug-05 19:38 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
DaveC42691319-Aug-05 3:27
DaveC42691319-Aug-05 3:27 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
progload19-Aug-05 3:50
progload19-Aug-05 3:50 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
DaveC42691319-Aug-05 4:24
DaveC42691319-Aug-05 4:24 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
progload19-Aug-05 4:53
progload19-Aug-05 4:53 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
DaveC42691319-Aug-05 5:20
DaveC42691319-Aug-05 5:20 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
Christian Graus21-Aug-05 19:19
protectorChristian Graus21-Aug-05 19:19 
AnswerRe: VBer new to VB.net - handles divide by zero? Pin
Thomas Stockwell19-Aug-05 8:32
professionalThomas Stockwell19-Aug-05 8:32 
GeneralRe: VBer new to VB.net - handles divide by zero? Pin
rwestgraham19-Aug-05 9:05
rwestgraham19-Aug-05 9:05 
Generalcombing a vb program with office command ! Pin
microuser_200018-Aug-05 9:08
microuser_200018-Aug-05 9:08 
GeneralRe: combing a vb program with office command ! Pin
microuser_200021-Aug-05 8:00
microuser_200021-Aug-05 8:00 
GeneralRe: combing a vb program with office command ! Pin
Steve Pullan21-Aug-05 14:20
Steve Pullan21-Aug-05 14:20 
Generalmulticolumn combobox Pin
sifferbo18-Aug-05 8:39
sifferbo18-Aug-05 8:39 
GeneralSoftwares sharing file Pin
loicmichel18-Aug-05 5:48
loicmichel18-Aug-05 5:48 
GeneralRe: Softwares sharing file Pin
Christian Graus18-Aug-05 15:11
protectorChristian Graus18-Aug-05 15:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.