Click here to Skip to main content
15,895,084 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: VB2008 How do i.... Pin
#realJSOP29-May-09 11:12
mve#realJSOP29-May-09 11:12 
QuestionRetrieving DataGridViewComboBoxColumn Values Pin
Roger Rainey29-May-09 3:00
Roger Rainey29-May-09 3:00 
AnswerRe: Retrieving DataGridViewComboBoxColumn Values Pin
Dave Kreskowiak29-May-09 3:48
mveDave Kreskowiak29-May-09 3:48 
QuestionDelete folder containing files and sub-folder. Pin
Gagan.2028-May-09 23:35
Gagan.2028-May-09 23:35 
AnswerRe: Delete folder containing files and sub-folder. Pin
AhsanS29-May-09 0:12
AhsanS29-May-09 0:12 
AnswerRe: Delete folder containing files and sub-folder. Pin
0x3c029-May-09 0:31
0x3c029-May-09 0:31 
AnswerRe: Delete folder containing files and sub-folder. Pin
Jon_Boy29-May-09 1:58
Jon_Boy29-May-09 1:58 
QuestionVB.Net Compiler Warning.......'used before assigned a value. null exception could result'. Pin
DaveAuld28-May-09 22:58
professionalDaveAuld28-May-09 22:58 
Hi folks,

I am looking for a bit of guidance on the best way to structure the following code to prevent the compiler warning.

The code works and does what it should, i just don't want to have the warning message sitting there all the time.

Bascially, the code polls a database for a list of values and returns them to the caller as a list(of String).

Public Function GetPlatformList() As List(Of String)

    Dim result As New List(Of String)
    Dim dbCon As New OleDb.OleDbConnection(dbConnectionString)

    Dim dbCMD As OleDb.OleDbCommand
    Dim dbReader As OleDb.OleDbDataReader

    dbCMD = New OleDb.OleDbCommand("SELECT PlatformName FROM Platforms", dbCon)

    Try
        dbCon.Open()

        dbReader = dbCMD.ExecuteReader()
        Dim HasResult As Boolean = True
        Do Until Not HasResult
            Do While dbReader.Read()
                result.Add(dbReader.GetString(0))
            Loop
            HasResult = dbReader.NextResult()
        Loop

    Catch ex As Exception
        'Error Trying
        MsgBox("Error Accessing Database: " & ex.Message, MsgBoxStyle.Critical, "Database Error")
    End Try

    dbReader.Close()
    dbCon.Close()

    'Return the list of platforms
    Return result
End Function


I have tried coding this different ways, and this is following the examples in MSDN etc, but i always end up with the compiler waring;
Variable 'dbReader' is used before it has been assigned a value. A null reference exception could result at runtime.


The guidance I am looking for is how to structure it in such a way as to prevent the warning.

Thanks,
dave


AnswerRe: VB.Net Compiler Warning.......'used before assigned a value. null exception could result'. Pin
DidiKunz28-May-09 23:03
DidiKunz28-May-09 23:03 
GeneralRe: VB.Net Compiler Warning.......'used before assigned a value. null exception could result'. Pin
DaveAuld28-May-09 23:19
professionalDaveAuld28-May-09 23:19 
AnswerRe: VB.Net Compiler Warning.......'used before assigned a value. null exception could result'. [modified] Pin
Luc Pattyn29-May-09 1:30
sitebuilderLuc Pattyn29-May-09 1:30 
GeneralRe: VB.Net Compiler Warning.......'used before assigned a value. null exception could result'. Pin
DaveAuld29-May-09 2:03
professionalDaveAuld29-May-09 2:03 
GeneralRe: VB.Net Compiler Warning.......'used before assigned a value. null exception could result'. Pin
Luc Pattyn29-May-09 2:05
sitebuilderLuc Pattyn29-May-09 2:05 
AnswerRe: VB.Net Compiler Warning.......'used before assigned a value. null exception could result'. Pin
chilinhhacker14-Jul-09 16:03
chilinhhacker14-Jul-09 16:03 
QuestionVB6 application using BeforeNavigate2 to capture a filled web page no longer catching pop-ups Pin
hubdawgs28-May-09 17:00
hubdawgs28-May-09 17:00 
AnswerRe: VB6 application using BeforeNavigate2 to capture a filled web page no longer catching pop-ups Pin
Christian Graus28-May-09 21:18
protectorChristian Graus28-May-09 21:18 
GeneralRe: VB6 application using BeforeNavigate2 to capture a filled web page no longer catching pop-ups Pin
hubdawgs29-May-09 4:06
hubdawgs29-May-09 4:06 
QuestionFTP Download problems Pin
CodecCodes28-May-09 15:32
CodecCodes28-May-09 15:32 
AnswerRe: FTP Download problems Pin
Dave Kreskowiak28-May-09 17:33
mveDave Kreskowiak28-May-09 17:33 
Questionworksheetfunction.match Pin
yamanbas28-May-09 8:41
yamanbas28-May-09 8:41 
QuestionGet data off a grid on a web page Pin
MarDude28-May-09 5:54
MarDude28-May-09 5:54 
AnswerRe: Get data off a grid on a web page Pin
Jay Royall28-May-09 6:14
Jay Royall28-May-09 6:14 
GeneralRe: Get data off a grid on a web page Pin
MarDude28-May-09 7:11
MarDude28-May-09 7:11 
GeneralRe: Get data off a grid on a web page Pin
Jay Royall28-May-09 8:22
Jay Royall28-May-09 8:22 
GeneralRe: Get data off a grid on a web page Pin
MarDude28-May-09 13:33
MarDude28-May-09 13:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.