![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
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))
NextThe red line has error attached to it saying object reference not set to an instance of an object |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
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)
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)
__________________
I have never let my schooling interfere with my education. -Mark Twain- Xbox live gamertag: melbolt |
|
|
|
|
|
#3 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
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.
|
|
|
|
|
|
#4 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |