Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 4th, 2007, 3:04 AM   #1
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 272
Rep Power: 2 Jabo is on a distinguished road
Object reference error

I'm trying to make a parser for a text file, but I'm getting an object reference error. Can somebody tell me why?
Dim filereader As String
        Dim parser() As String
        Dim ArrSize, i, j, x As Integer
        Dim word(), newword() As Char

        filereader = My.Computer.FileSystem.ReadAllText("m:\VC++Express\Open Media Distribution List[1].txt")
        parser = Split(filereader)
        ArrSize = parser.Length
        For i = 0 To ArrSize - 1
            word = parser(i).ToCharArray
            x = word.Length
            For j = 0 To x - 1
                If Char.IsLetterOrDigit(word(j)) Then
                    newword(newword.Length) = word(j)
                End If
            Next
            parser(i) = newword.ToString
            lboTSMTape.Items.Add(parser(i))
        Next

The red line has error attached to it saying object reference not set to an instance of an object
Jabo is offline   Reply With Quote
Old Oct 4th, 2007, 9:02 AM   #2
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 242
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
let me see if I can explain this right.

here's the problem, you attempt to put something in the array newword but you never allocated any space for that array.

what i mean by this is, you never gave it bounds ex: newword(5) would allocate 5 indexes.

what you can do is this...
vbnet Syntax (Toggle Plain Text)
  1. word = parser(i).ToCharArray
  2. Dim newword(word.Length) As Char

the reason you didn't have to set up the word array like this is because you are not trying to utilize its indexes until you set it equal to an existing array(which does have allocated memory)
ex:
vbnet Syntax (Toggle Plain Text)
  1. word = parser(i).ToCharArray
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Old Oct 4th, 2007, 9:07 AM   #3
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 272
Rep Power: 2 Jabo is on a distinguished road
Ahh, that makes a lot of sense, thanks melbolt. But now i'm gonna have to rethink my algorithm because the array will be different each time. Can you dynamically allocate a vector? I need to re-learn how to do a vector.
Jabo is offline   Reply With Quote
Old Oct 5th, 2007, 2:37 AM   #4
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 272
Rep Power: 2 Jabo is on a distinguished road
Here's what I wound up doing; it's not elegant, but it does the job.
Dim filereader As String
        Dim parser() As String
        Dim ArrSize, i, j, x, y As Integer
        Dim word(30), newword(30) As Char

        filereader = My.Computer.FileSystem.ReadAllText(cboFileList.Text)
        parser = Split(filereader)
        ArrSize = parser.Length

        For i = 0 To ArrSize - 1
            word = parser(i).ToCharArray
            x = word.Length
            y = 0
            For j = 0 To 29
                newword(j) = ""
            Next
            For j = 0 To x - 1
                If (Char.IsLetterOrDigit(word(j))) Then
                    newword(y) = word(j)
                    y = y + 1
                End If
            Next
            parser(i) = newword
            If parser(i).Substring(0, 2) = "CD" Or parser(i).Substring(0, 2) = "00" Then
                lboTSMTape.Items.Add(parser(i))
            End If
        Next
Jabo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Socket Programming Error in Linux.. Pls help boraciner C++ 18 Sep 12th, 2007 1:17 AM
Header file internal errors kruptof Coder's Corner Lounge 2 Jan 14th, 2007 1:12 PM
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
libraries matko C 1 Jan 22nd, 2006 2:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC