Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Use of variable prior to assignment in VB 2005
Message
De
14/06/2007 10:12:35
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
14/06/2007 09:48:37
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01232383
Message ID:
01233007
Vues:
8
>>DOH! You know what? I dummied the code sample up after I pasted it and took the CASE statement out. So should I be initializing these classes to NOTHING when I declare them?
>
>If you have a CASE statement in there, then what the compiler is objecting to is that you most likely *don't* have a default for that CASE. IOW, there's no guarantee that your variable will be assigned to something, so it could very well be unassigned at runtime when you hit the return statement. The solution is to have a DEFAULT for your CASE (or whatever the VB-syntax is for that) and assign the variable to nothing there.
>
>~~Bonnie

I see... so I could have a CASE ELSE that set the object to NOTHING? I will try. Now maybe I can shut the darn compiler up!

>
>
>
>>
>>
>>>That doesn't make sense that you're getting a warning ... you *are* setting the myHistoricalRatesDS in the statement right before the return. I don't get why you have a warning. Now, if you had an if statement in there, it would make sense to me, but the way you're showed it here, it doesn't make sense that there should be a warning.
>>>
>>>Of course, I don't use VB, so what do I know?!?!? <g>
>>>
>>>~~Bonnie
>>>
>>>
>>>>I keep getting a lot of "Use of variable prior to assignment" warnings in VB 2005. I know that I can turn them off at the project level and usually do this, but it makes me suspicious that maybe I am doing something that I shouldn't. Here is a snippet in a business class:
>>>>
>>>>
>>>>    Public Function LoadHistoricalRates() As HistoricalRatesDS
>>>>
>>>>        'This is my data access class...
>>>>        Dim myHistoricalRatesData As New HistoricalRatesData
>>>>        'This is my dataset.  I don't instantiate it here because it is instantiated
>>>>        'in my data access class...
>>>>        Dim myHistoricalRatesDS As HistoricalRatesDS
>>>>
>>>>        'An instance of HistoricalRatesDS is instantiated in my data access
>>>>        'class so I don't instantiate it again...
>>>>        myHistoricalRatesDS = myHistoricalRatesData.LoadHistoricalRates
>>>>
>>>>        'Here is where I get the warning...
>>>>        Return myHistoricalRatesDS
>>>>
>>>>    End Function
>>>>
Very fitting: http://xkcd.com/386/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform