.NET 1.1 Bug? If Boolean Then DoThis()

Published 22 July 05 12:20 PM | dwalker 

I had a problem with some code tonight that drove me crazy!
It used to work, but now it doesn't!

I have a Method (Function) called IsValid, for example, that returns Boolean.

Public Function IsValid(TestText As String) As Boolean
    If TestText = "Test" Then
        Return True
    Else
        Return False
    End If
End Function

I then had some code that said:

If Not IsValid(TestText.Text) Then lblResults.Text = "Wrong"


All of the sudden it just quit working, so I stepped through it and it looked correct, but BOOM, it kept going saying "Wrong, even if it was right!

So, I tried adding this line:

Dim CheckValid As Boolean = IsValid(TestText.Text)


CheckValid was returning correctly!
So, I finally tried this:

If Not IsValid(TestText.Text) Then
    lblResults.Text = "Wrong"
End If

For some reason, it required the If -- Then to be on separate lines and that of course required the End If. Oh, well, it's a little more readable that way anyway, but still, it's just the point!

Sponsor
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# dwalker said on July 22, 2005 4:33 PM:
I've encountered that but couldn't replicate the problem reliably in a smaller test project to inquire the community and submit to microsoft as a defect.

This was 2 years ago (in the 1.0) days. I'm glad someone was able to replicate the problem. It is actually the reason now that I am so religious about breaking the if-then statements on seperate lines (a habbit that I'm unlikely to break now).

Thanks,
Shawn
# dwalker said on July 28, 2005 12:48 PM:
I agree Shawn! It definitely helps break the habbit!

It's just a shame for insanely simple if statements to then require the extra lines. Oh well. It will help against the temptation from doing it to larger if statements as well! :)

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below

About dwalker

David Walker has over 15 years experience in application development with over 50% of that employed as a consultant with companies such as: Texaco, Bank of Oklahoma, Winner Communications (ESPN.com) and IBM Global Services. At the age of 14, he began his application development ambitions with a Commodore 64, BASIC, and a 300 baud modem. Even at that early age, he primarily focused on two specific application types: multi-user communities and database applications.

His hunger to learn as much as possible about development lead him through courses such as DBase III, DBase IV, Pascal, C, C++, Java, and several in UNIX. He started his development career first doing heavy processing with Access and VBA, then moved on to VB 3, Oracle, and Delphi. Visual Basic was one environment that remained constant for many years, including his very first .NET projects performed in Visual Basic.NET.

After working several years on very high end internal Corporate applications, the consultant company he was working for, sought out his ideas for actual software products that could be packaged and sold. He had already developed several prototypes of a dynamic portal application, before portals even became popular, so this became the logic decision and he became the Director of Product Development. Under his direction, a team of developers and graphic artists, took a skinning approach before that become popular, and completed the core portal application, and continued on to developer 15+ add-on modules, including things such as: Help Desk Ticket Systems, Change Control, Records Management, Human Resources, and many more applications. Eventually, it spun off into it's own separate company as KnowledgeGEAR, a complete intranet in the box solution.

Having worked as a consultant, he has had a experience with a very wide range of applications and architectures, at one time, even converting several Fox Pro and GW-Basic applications to VB 6 and ASP. His early training of Unix and the C language and years of experience with JavaScript, lead him very quickly to C#, where he has remained focused ever since.

He is the current President of the Tulsa Developers .NET user group.. He has been an MCP since 2003 and MCAD and MCSD since 2005. He is currently pursuing his MCDBA and then on to MCSE.

Search

Go

This Blog

Tags

Archives

My Blog Roll (Partial)

My Sites

Syndication