Blog of a Filipino Developer about C#, VB.NET, ASP.NET, Java, PHP, SQL Server, MySql and Oracle RSS 2.0
 Saturday, May 26, 2007

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 12:06:49 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET
Comments are closed.
On this page
Archive
<October 2008>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
About the author/Disclaimer

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

© Copyright 2008
Keith Rull
Sign In
Statistics
Total Posts: 254
This Year: 51
This Month: 0
This Week: 0
Comments: 111
Themes
Pick a theme:
Ads
All Content © 2008, Keith Rull
DasBlog theme 'Business' created by Christoph De Baene (delarou)