473,811 Members | 3,260 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object not set to an instance

The following line is creating the above error message.

tree_nodes((lev el)-1).Nodes.Add(tr ee_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.Lengt h - text_line.TrimS tart.Length

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

Dim stream_reader As New System.IO.Strea mReader(file_na me)
Dim file_contents As String = stream_reader.R eadToEnd()
stream_reader.C lose()

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

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

' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As Microsoft.Web.U I.WebControls.T reeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_ nodes)

trv.Nodes.Clear ()
For i As Integer = 0 To lines.GetUpperB ound(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.Lengt h - text_line.TrimS tart.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(lev el) = trv.Nodes.Add(t ext_line.Trim() )
tree_nodes(leve l) = New TreeNode
tree_nodes(leve l).Text = CStr(text_line. Trim())

trv.Nodes.Add(t ree_nodes(level ))

Else
' tree_nodes(leve l) = tree_nodes(leve l -
1).Nodes.Add(te xt_line.Trim())
tree_nodes(leve l) = New TreeNode
tree_nodes(leve l).Text = CStr(text_line. Trim())
tree_nodes((lev el)-1).Nodes.Add(tr ee_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 1124
In the statement:

tree_nodes((lev el)-1).Nodes.Add(tr ee_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(leve l-1)
tree_nodes(leve l-1).Nodes
tree_nodes(leve l)

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(leve l-1)
tree_nodes(leve l)

That should narrow it down for you.

--
HTH,

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

"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:06******** *************** ***********@mic rosoft.com...
The following line is creating the above error message.

tree_nodes((lev el)-1).Nodes.Add(tr ee_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.Lengt h - text_line.TrimS tart.Length

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

Dim stream_reader As New System.IO.Strea mReader(file_na me)
Dim file_contents As String = stream_reader.R eadToEnd()
stream_reader.C lose()

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

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

' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As Microsoft.Web.U I.WebControls.T reeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_ nodes)

trv.Nodes.Clear ()
For i As Integer = 0 To lines.GetUpperB ound(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.Lengt h - text_line.TrimS tart.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(lev el) = trv.Nodes.Add(t ext_line.Trim() )
tree_nodes(leve l) = New TreeNode
tree_nodes(leve l).Text = CStr(text_line. Trim())

trv.Nodes.Add(t ree_nodes(level ))

Else
' tree_nodes(leve l) = tree_nodes(leve l -
1).Nodes.Add(te xt_line.Trim())
tree_nodes(leve l) = New TreeNode
tree_nodes(leve l).Text = CStr(text_line. Trim())
tree_nodes((lev el)-1).Nodes.Add(tr ee_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.Lengt h - text_line.TrimS tart(vbTab).Len gth

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((lev el)-1).Nodes.Add(tr ee_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(leve l-1)
tree_nodes(leve l-1).Nodes
tree_nodes(leve l)

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(leve l-1)
tree_nodes(leve l)

That should narrow it down for you.

--
HTH,

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

"Hutty" <Hu***@discussi ons.microsoft.c om> wrote in message
news:06******** *************** ***********@mic rosoft.com...
The following line is creating the above error message.

tree_nodes((lev el)-1).Nodes.Add(tr ee_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.Lengt h - text_line.TrimS tart.Length

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

Dim stream_reader As New System.IO.Strea mReader(file_na me)
Dim file_contents As String = stream_reader.R eadToEnd()
stream_reader.C lose()

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

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

' Process the lines.
Dim text_line As String
Dim level As Integer
Dim tree_nodes() As Microsoft.Web.U I.WebControls.T reeNode
Dim num_nodes As Integer = 0
ReDim tree_nodes(num_ nodes)

trv.Nodes.Clear ()
For i As Integer = 0 To lines.GetUpperB ound(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.Lengt h - text_line.TrimS tart.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(lev el) = trv.Nodes.Add(t ext_line.Trim() )
tree_nodes(leve l) = New TreeNode
tree_nodes(leve l).Text = CStr(text_line. Trim())

trv.Nodes.Add(t ree_nodes(level ))

Else
' tree_nodes(leve l) = tree_nodes(leve l -
1).Nodes.Add(te xt_line.Trim())
tree_nodes(leve l) = New TreeNode
tree_nodes(leve l).Text = CStr(text_line. Trim())
tree_nodes((lev el)-1).Nodes.Add(tr ee_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
1614
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 handle the data: class DataWrapper():
18
3055
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 a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
2
2983
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 Intel compiler it has stopped working. I think the singleton pattern static instance thing may be at the root of the problem, but I'm not sure. I had to add calls to instance() in regCreateFn, which gets the behaviour more in line with what I was...
6
22541
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 instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
4
1889
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 browsers) ? What about the new syntax of creating a object using { 'propName1':'propValue1', 'propName2':'propValue2', 'propName3':{ /* another object */ } } - from what version of JScript/JavaScript it was supported (from what browsers versions) ?...
11
3851
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 experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of ways to do this through prototyping and other techniques, but these behaviors need to be static and...
12
5560
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. Foo = function(type) { this.num = 0; this.type = type this.trigger(); } Foo.prototype.trigger = function() {
6
2483
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
2662
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
3180
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 instance is created by "calling" a class object.
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10397
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10138
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7674
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5564
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3878
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3027
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.