Vb.NET bugs

kata79

New member
Joined
Jan 2, 2006
Messages
2
Programming Experience
Beginner
Could you write for me a list of errors which you commit during programming (logic errors, run-time errors) and some examples? Thanks for replays
 
Umm.. Why? The compiler does that (i.e. the wiggly lines under all the erroneous stuff you write)

If youre talking about logical flow errors.. Er, I think it would take me a good few hours to remember the 5 or 6 errors I've made over the years I've been programming, but if any spring to mind while I'm working, I'll let you know :)
 
Logic error:

VB.NET:
If myObject Is Nothing Then
    '...
End If

If you meant to test if the object was NOT nothing (i.e. "If myObject IsNot Nothing"), that could be considered a simple logic error.

Run time error:

VB.NET:
Dim X As ArrayList
X.Add("Hello world!")

Would result in a runtime error because, even though ADD is a valid method for the ArrayList class, you cannot ADD to an ArrayList unless it is has an instance/reference to work with (i.e. unless it has been instantiated with:)

VB.NET:
Dim X As New ArrayList

If ArrayList had a Shared "Add" method, then there would be no runtime error. But it doesn't, so you need to declare it with "Dim ... As New ArrayList"
 
Logic error:

VB.NET:
If myObject Is Nothing Then
    '...
End If

If you meant to test if the object was NOT nothing (i.e. "If myObject IsNot Nothing"), that could be considered a simple logic error.

Yeah, but that's kinda silly.. Youre right, but what are you going to do.. Fill a whole thread with things on the same banal level as "Make sure you write NOT if youre checking for something that is the opposite of what the check method does" - it's about as useful as saying "if you want to test that a String contains some text, dont use the Replace() method"

i.e. if a coder cant figure out what the error is here, and needs to be told in advance just so they can avoid it.. They probably dont have the intellectual capacity to be a programmer. I dont mean to sound elitist, but really, there are some problems that are meant to weed out the non-hackers

Run time error:

VB.NET:
Dim X As ArrayList
X.Add("Hello world!")

I'd actually expect that to raise a compiler warning or error "Use of un-instanciated variable X"



If ArrayList had a Shared "Add" method, then there would be no runtime error. But it doesn't, so you need to declare it with "Dim ... As New ArrayList"

Similarly if the coder is calling a shared method on an instance, a warning of "Use of shared member via instance variable; qualifying result will not be evaluated" or something, appears...
 
I'd actually expect that to raise a compiler warning or error "Use of un-instanciated variable X"

Not in VS 2005 at least.

Yeah, but that's kinda silly.. Youre right, but what are you going to do..

Hence why I qualified my statement with "simple logic error". :)
 
It produces this warning in VS2005:
Variable 'X' is used before it has been assigned a value. A null reference exception could result at runtime.
 
Not in VS 2005 at least.
I couldnt remember the exact error message, but I was sure i'd seen it.
Maybe you should program with Option Strict On, Option Explicit On ?
 

Attachments

  • Image1.png
    Image1.png
    16.6 KB · Views: 42
Basically that error is telling you that you have not declared anything for "s". It knows it is a string object, but it doesnt hold any value.
 
I do program with Explicit and Strict to On. Always have. And that example happens. But not when you do:

VB.NET:
Public Class MyClass
    Private X As ArrayList

    Public Sub New()
        X.Add("Test")
    End Sub
End Class

That produces no errors or warnings until run-time. Hence why this would be a runtime error and why I said that in my first post in this thread.
 
Last edited:
Actually it give this error about "MyClass":
Keyword is not valid as an identifier.
:) but you're right about the instance in this case.
 
Umm, what? I think you're confused.

"X" is of type ArrayList, not of type MyClass. ArrayList does in fact have "Add" as a keyword. So I think you need to re-read what I typed.

If you drop that into a code file and use it, it will generate absolutely ZERO errors and ZERO warnings until runtime, and then only when the class is instantiated.
 
Umm, what? I think you're confused.

Buaaahahaha.. I think we should rename this thread:

Could you write for me a list of errors which you commit during posting (on teh interweb) and some examples? Thanks for replays

;) ;)

To be fair, rfaricy, you HAVE changed the premise of your example. You've gone from Dimming a local variable, to Dimming a class wide variable. One does raise the "Use of unassigned local variable" (because its local) the other, does not (because it's class wide, maybe assigned elsewhere, the IDE doesnt look that hard at it) ;)
 
Back
Top