Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Looking to resolve a warning
Message
De
16/12/2005 18:17:55
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Looking to resolve a warning
Divers
Thread ID:
01078852
Message ID:
01078852
Vues:
59
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform