473,396 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Object not set to an instance

The following line is creating the above error message.

tree_nodes((level)-1).Nodes.Add(tree_nodes(level))

It's because of the following line where I'm trying to calculate the length of
blank spaces and substracting from total length.

level = text_line.Length - text_line.TrimStart.Length

Here's the code. The first part of the "IF" is fine.

Dim stream_reader As New System.IO.StreamReader(file_name)
Dim file_contents As String = stream_reader.ReadToEnd()
stream_reader.Close()

' Remove line feeds.
file_contents = file_contents.Replace(vbLf, "")

' Break the file into lines.
Const charCR As Char = CChar(vbCr)
'Const charTab As Char = CChar(vbTab)
Dim lines() As String = file_contents.Split(charCR)

' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As Microsoft.Web.UI.WebControls.TreeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_nodes)

trv.Nodes.Clear()
For i As Integer = 0 To lines.GetUpperBound(0)
text_line = lines(i)
If text_line.Trim().Length > 0 Then
' See how many tabs are at the start of the line.

level = text_line.Length - text_line.TrimStart.Length

' Make room for the new node.
If level > num_nodes Then
num_nodes = level
ReDim Preserve tree_nodes(num_nodes)
End If

' Add the new node.
If level = 0 Then
'tree_nodes(level) = trv.Nodes.Add(text_line.Trim())
tree_nodes(level) = New TreeNode
tree_nodes(level).Text = CStr(text_line.Trim())

trv.Nodes.Add(tree_nodes(level))

Else
' tree_nodes(level) = tree_nodes(level -
1).Nodes.Add(text_line.Trim())
tree_nodes(level) = New TreeNode
tree_nodes(level).Text = CStr(text_line.Trim())
tree_nodes((level)-1).Nodes.Add(tree_nodes(level))
End If

I'm reading from a file that has indentation based on spaces. If it was a
true tab-delimited file I would be okay. So, it's the blank spaces that
would determine order of the nodes. Thanks in advance.

--
Hutty
Nov 19 '05 #1
2 1111
In the statement:

tree_nodes((level)-1).Nodes.Add(tree_nodes(level))

There are 4 object references. One of them is not an instance of an object.
The 4 references are:

tree_nodes
tree_nodes(level-1)
tree_nodes(level-1).Nodes
tree_nodes(level)

Assuming that tree_nodes is an instance of an object, and that if there is
an instance of a tree_node that it will have an instance of Nodes, you
actually have 2 object references to check:

tree_nodes(level-1)
tree_nodes(level)

That should narrow it down for you.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Hutty" <Hu***@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
The following line is creating the above error message.

tree_nodes((level)-1).Nodes.Add(tree_nodes(level))

It's because of the following line where I'm trying to calculate the
length of
blank spaces and substracting from total length.

level = text_line.Length - text_line.TrimStart.Length

Here's the code. The first part of the "IF" is fine.

Dim stream_reader As New System.IO.StreamReader(file_name)
Dim file_contents As String = stream_reader.ReadToEnd()
stream_reader.Close()

' Remove line feeds.
file_contents = file_contents.Replace(vbLf, "")

' Break the file into lines.
Const charCR As Char = CChar(vbCr)
'Const charTab As Char = CChar(vbTab)
Dim lines() As String = file_contents.Split(charCR)

' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As Microsoft.Web.UI.WebControls.TreeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_nodes)

trv.Nodes.Clear()
For i As Integer = 0 To lines.GetUpperBound(0)
text_line = lines(i)
If text_line.Trim().Length > 0 Then
' See how many tabs are at the start of the line.

level = text_line.Length - text_line.TrimStart.Length

' Make room for the new node.
If level > num_nodes Then
num_nodes = level
ReDim Preserve tree_nodes(num_nodes)
End If

' Add the new node.
If level = 0 Then
'tree_nodes(level) = trv.Nodes.Add(text_line.Trim())
tree_nodes(level) = New TreeNode
tree_nodes(level).Text = CStr(text_line.Trim())

trv.Nodes.Add(tree_nodes(level))

Else
' tree_nodes(level) = tree_nodes(level -
1).Nodes.Add(text_line.Trim())
tree_nodes(level) = New TreeNode
tree_nodes(level).Text = CStr(text_line.Trim())
tree_nodes((level)-1).Nodes.Add(tree_nodes(level))
End If

I'm reading from a file that has indentation based on spaces. If it was a
true tab-delimited file I would be okay. So, it's the blank spaces that
would determine order of the nodes. Thanks in advance.

--
Hutty

Nov 19 '05 #2
Thanks for the reply. I'm sure it's the (level)-1 that is causing it. The
code was originally set to work on tab delimited and had the following
relationship.

Const charTab As Char = CChar(vbTab)
level = text_line.Length - text_line.TrimStart(vbTab).Length

Since I have spaces instead of tabs in the file I took out the "vbtab", and
that's what is causing error. Referencing the spaces instead of tabs is
where I'm hung up.
"Kevin Spencer" wrote:
In the statement:

tree_nodes((level)-1).Nodes.Add(tree_nodes(level))

There are 4 object references. One of them is not an instance of an object.
The 4 references are:

tree_nodes
tree_nodes(level-1)
tree_nodes(level-1).Nodes
tree_nodes(level)

Assuming that tree_nodes is an instance of an object, and that if there is
an instance of a tree_node that it will have an instance of Nodes, you
actually have 2 object references to check:

tree_nodes(level-1)
tree_nodes(level)

That should narrow it down for you.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Hutty" <Hu***@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
The following line is creating the above error message.

tree_nodes((level)-1).Nodes.Add(tree_nodes(level))

It's because of the following line where I'm trying to calculate the
length of
blank spaces and substracting from total length.

level = text_line.Length - text_line.TrimStart.Length

Here's the code. The first part of the "IF" is fine.

Dim stream_reader As New System.IO.StreamReader(file_name)
Dim file_contents As String = stream_reader.ReadToEnd()
stream_reader.Close()

' Remove line feeds.
file_contents = file_contents.Replace(vbLf, "")

' Break the file into lines.
Const charCR As Char = CChar(vbCr)
'Const charTab As Char = CChar(vbTab)
Dim lines() As String = file_contents.Split(charCR)

' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As Microsoft.Web.UI.WebControls.TreeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_nodes)

trv.Nodes.Clear()
For i As Integer = 0 To lines.GetUpperBound(0)
text_line = lines(i)
If text_line.Trim().Length > 0 Then
' See how many tabs are at the start of the line.

level = text_line.Length - text_line.TrimStart.Length

' Make room for the new node.
If level > num_nodes Then
num_nodes = level
ReDim Preserve tree_nodes(num_nodes)
End If

' Add the new node.
If level = 0 Then
'tree_nodes(level) = trv.Nodes.Add(text_line.Trim())
tree_nodes(level) = New TreeNode
tree_nodes(level).Text = CStr(text_line.Trim())

trv.Nodes.Add(tree_nodes(level))

Else
' tree_nodes(level) = tree_nodes(level -
1).Nodes.Add(text_line.Trim())
tree_nodes(level) = New TreeNode
tree_nodes(level).Text = CStr(text_line.Trim())
tree_nodes((level)-1).Nodes.Add(tree_nodes(level))
End If

I'm reading from a file that has indentation based on spaces. If it was a
true tab-delimited file I would be okay. So, it's the blank spaces that
would determine order of the nodes. Thanks in advance.

--
Hutty


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Uwe Mayer | last post by:
Hi, sorry for the lack of source code. Here again: I use struct.unpack() to unpack data from a binary file and pass the returned tuple as parameter to __init__ of a class that's supposed to...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
2
by: Ryan Mitchley | last post by:
Hi all I have code for an object factory, heavily based on an article by Jim Hyslop (although I've made minor modifications). The factory was working fine using g++, but since switching to the...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
4
by: Luke Matuszewski | last post by:
Here are some questions that i am interested about and wanted to here an explanation/discussion: 1. (general) Is the objectness in JavaScript was supported from the very first version of it (in...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
6
by: Shailen Sukul | last post by:
Observed a weird behaviour with object references. See code listing below: using System; using System.Collections.Generic; using System.Text; namespace PointerExceptionTest { /*
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
5
by: JH | last post by:
Hi I found that a type/class are both a subclass and a instance of base type "object". It conflicts to my understanding that: 1.) a type/class object is created from class statement 2.) a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.