A VB.NET Bug ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

One of the articles I read touting the new changes with VB.NET, mentioned that VB now optimized it's compilation so that

Line 605: Return
Line 606: Els
Line 607: If IsNothing(ts) Or ts.Length = 0 Then <-------This lin
Line 608: Return ds.Tables("CASE").Rows.Coun
Line 609: Els

should not crash when ts = nothing. The isNothing(ts) evaluates to TRUE, so the Or statement is true without checking the second half of the statement

The above lines of code are from the Exception screen displayed when the ts was discovered not to be a valid Object reference. That would only have been an error if it needlessly (and against the rule I recall reading, although to be honest, I can't (or won't) find them now)
 
Take a look at the VS-Help for "AndAlso" and "OrElse", that should help.

Klaus


mklapp said:
One of the articles I read touting the new changes with VB.NET, mentioned
that VB now optimized it's compilation so that :
Line 605: Return 0
Line 606: Else
Line 607: If IsNothing(ts) Or ts.Length = 0 Then <-------This line
Line 608: Return ds.Tables("CASE").Rows.Count
Line 609: Else

should not crash when ts = nothing. The isNothing(ts) evaluates to TRUE,
so the Or statement is true without checking the second half of the
statement.
The above lines of code are from the Exception screen displayed when the
ts was discovered not to be a valid Object reference. That would only have
been an error if it needlessly (and against the rule I recall reading,
although to be honest, I can't (or won't) find them now).
 
HI
The functionality was change back to VB6 style
due to user pressure and upgrade issues from VB6 ( I read that somewhere )

copy the following to a new project and when you run it you will see
both the property's being called even though getX is true

Shame I was looking forward to this new feature,
I believe C# works fine with this new implementation( OK not new other
languages have always worked this way )

Cheers
James

Private x As Boolean = True, y As Boolean = False

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If GetX Or Gety Then

MsgBox("OK")

Else

MsgBox("Fail")

End If

End Sub

Public ReadOnly Property GetX() As Boolean

Get

Return x

End Get

End Property

Public ReadOnly Property Gety() As Boolean

Get

Return y

End Get

End Property


mklapp said:
One of the articles I read touting the new changes with VB.NET, mentioned
that VB now optimized it's compilation so that :
Line 605: Return 0
Line 606: Else
Line 607: If IsNothing(ts) Or ts.Length = 0 Then <-------This line
Line 608: Return ds.Tables("CASE").Rows.Count
Line 609: Else

should not crash when ts = nothing. The isNothing(ts) evaluates to TRUE,
so the Or statement is true without checking the second half of the
statement.
The above lines of code are from the Exception screen displayed when the
ts was discovered not to be a valid Object reference. That would only have
been an error if it needlessly (and against the rule I recall reading,
although to be honest, I can't (or won't) find them now).
 
Oops I boobed
Why did I not remember that part of the article I read?
OK I give up ( it was a long day )
Klaus is most correct

Thanks for a better response than mine. I will try to get it right next
time
Cheers
James
 
Hi Mklapp,

In addition to Klaus (when someone really had telled me the reason for those
OrElse and AndAlso I started to find it nice operators) that statement from
you should be written when there were no OreElse and AndAlso.

If Not ts Is Nothing then
If ts.Length <> 0 then
return...
end if
end if

I hope this helps,

Cor
 
Hi mklapp,

Does the community's reply make sense to you?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top