Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looking to resolve a warning
Message
From
16/12/2005 18:17:55
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Looking to resolve a warning
Miscellaneous
Thread ID:
01078852
Message ID:
01078852
Views:
58
Since I have upgraded to VS 2005, I have a warning with the following code:
        Dim loDirectory As New DirectoryInfo(Input.Text)
        Dim loFileList As FileInfo() = loDirectory.GetFiles("*.xml")
        Dim loFile As FileInfo

        Try

            ' Get all the files in this one
            For Each loFile In loFileList
                lcFile = Input.Text + "\" + loFile.Name
            Next

        Catch loError As Exception
            lnEnd = Date.Now.Ticks
            lcHTMLLocal = ""
            lcHTMLLocal = lcHTMLLocal + "<TR VALIGN=TOP>"
            lcHTMLLocal = lcHTMLLocal + "<TD>Sending " + Input.Text + "\" + loFile.Name
        End Try
The message is "Variable 'loFile' is used before it has been assigned a value. A null reference exception could result at runtime".

This is in regards to the last line in the Catch. However, in this case, loFile is not initialized in the Catch because it is only initialized during the For Next which is in the Try. So, how can I adjust this code to avoid the warning?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform