Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

MSVS 8, VB "NullReferenceException"

This topic is 4860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I know that I am supposed to set my variables to new values, but I have been working on this for hours trying to get it to allow me to set my value for the string. I am used to VB 6 and the migration to the 2005 edition has been fine so far until this. Here's my code:
Public URLs As String()

    Public Sub LoadData()

        Dim LineIn As String, CIndex As Integer
        LineIn = Nothing : CIndex = 0

        Microsoft.VisualBasic.FileOpen(1, "Data\URLS.WWD", OpenMode.Input, OpenAccess.Read)
        While Not EOF(1)
            LineIn = Microsoft.VisualBasic.FileSystem.LineInput(1)

            If InStr(LineIn, "URL=", CompareMethod.Text) = 1 Then

                URLs(CIndex) = Mid(LineIn, 5, LineIn.Length - 4)
            End If

            CIndex = CIndex + 1
        End While
        Microsoft.VisualBasic.FileClose(1)
    End Sub

Now, the error is on the line URLs(CIndex) = Mid(LineIn, 5, LineIn.Length - 4). Why after all this time can't I get it to work? I even followed the MSDN directions here. Help?

Share this post


Link to post
Share on other sites
Advertisement
Oops.

Add

ReDim Preserve URLs(CIndex)

just before the line where you get the error.

You might also want to move the increment of CIndex inside the if statement. Otherwise, you will have some blank elements in your resulting array for lines that did not have "URL=" in them.

Share this post


Link to post
Share on other sites
All lines will have URL= in them. It will be a file that just stores a bunch of URLs for later use. That worked, thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!