A weird VB feature#

A friend asked me for help today about a segment of code that was giving him a headache. After looking at the code I immediately told him the problem. Can you spot the problem too without compiling the VB code? Why is it happening?

Module Program

    Sub Main()
        Calculate()
    End Sub

    Private Sub Calculate()
        Dim value1 As Integer = 0

        'Imagine that the value of value1 is has been manipulated on this section
        '///--> Insert imaginary code here <---

        Dim value2 As Integer = CInt(IIf(value1 <= 0, 100, CalculateValue(value1)))
    End Sub

    Private Function CalculateValue(ByVal value1 As Integer) As Integer
        If (value1 <= 0) Then
            Throw New ArgumentOutOfRangeException("Parameter cannot be less than 1!")
        Else
            Return CInt(100 / value1)
        End If
    End Function

End Module

*Note: Comments are welcome here.

Saturday, May 26, 2007 1:06:49 AM (GMT Daylight Time, UTC+01:00) #    Comments [0]  | 

 

Comments are closed.
All content © 2010, Keith Rull
On this page
This site
Calendar
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 2.3.9074.18820

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: