473,326 Members | 2,102 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,326 software developers and data experts.

VB 2003 - Odd Bug in My Program

*Confessor nods*

Okay, I've got a hell of a lead on how to read/write to Random Access
files, but there's a small problem that's stopping me short of sussing
out that whole thing.

The "arrowed" line of code (as well as the two lines following, if I skip
the first/second by commenting) pops the error 'Object reference not set
to an instance of an object,' no matter what I input into the textbox.

The problem can't be (MaxPoint), since Label5.Text confirms that it's
value is 1 prior to the execution of Button1_Click, and since no code (as
of yet) even *creates* points.dat, there's no situation in which its
value can be anything other than 1 following Form1_Load.

(Note that I've used ... to excise boring, simple parts in the following
code.)

Structure PointTemplate
Dim Latitude As Single
Dim Longitude As Single
Dim Elevation As Integer
End Structure
Dim MaxPoint As Integer
Dim Point() As PointTemplate

Private Sub Form1_Load(...) Handles MyBase.Load
If IO.File.Exists("C:\...\points.dat") Then
Else
MaxPoint = 1
End If
Label5.Text = MaxPoint
End Sub

Private Sub Button1_Click(...) Handles Button1.Click
---> Point(MaxPoint).Latitude = TextBox2.Text <---
Point(MaxPoint).Longitude = TextBox3.Text
Point(MaxPoint).Elevation = TextBox4.Text
MaxPoint = MaxPoint + 1
End Sub

Thanks in Advance,
The Confessor
Jan 6 '06 #1
4 940
Confessor,

I don't see where you have dimensioned your Point array to have any elements.

So you can't refer to Point (MaxPoint), where MaxPoint is 1, since there is
no element 1 in the Point array.

Kerry Moorman
"Confessor" wrote:
*Confessor nods*

Okay, I've got a hell of a lead on how to read/write to Random Access
files, but there's a small problem that's stopping me short of sussing
out that whole thing.

The "arrowed" line of code (as well as the two lines following, if I skip
the first/second by commenting) pops the error 'Object reference not set
to an instance of an object,' no matter what I input into the textbox.

The problem can't be (MaxPoint), since Label5.Text confirms that it's
value is 1 prior to the execution of Button1_Click, and since no code (as
of yet) even *creates* points.dat, there's no situation in which its
value can be anything other than 1 following Form1_Load.

(Note that I've used ... to excise boring, simple parts in the following
code.)

Structure PointTemplate
Dim Latitude As Single
Dim Longitude As Single
Dim Elevation As Integer
End Structure
Dim MaxPoint As Integer
Dim Point() As PointTemplate

Private Sub Form1_Load(...) Handles MyBase.Load
If IO.File.Exists("C:\...\points.dat") Then
Else
MaxPoint = 1
End If
Label5.Text = MaxPoint
End Sub

Private Sub Button1_Click(...) Handles Button1.Click
---> Point(MaxPoint).Latitude = TextBox2.Text <---
Point(MaxPoint).Longitude = TextBox3.Text
Point(MaxPoint).Elevation = TextBox4.Text
MaxPoint = MaxPoint + 1
End Sub

Thanks in Advance,
The Confessor

Jan 6 '06 #2
"=?Utf-8?B?S2VycnkgTW9vcm1hbg==?="
<Ke**********@discussions.microsoft.com> wrote in
news:0E**********************************@microsof t.com:
I don't see where you have dimensioned your Point array to have any
elements.

So you can't refer to Point (MaxPoint), where MaxPoint is 1, since
there is no element 1 in the Point array.

Kerry Moorman


So,

---> Dim Point([any frickin' number]) As PointTemplate <---

will do it, eh? Makes sense. Don't recall having this problem in a previous
project, but I'd forgotten that I'd specifically dimensioned that
particular array to (85)

Rather discouraging, as I was planning on having a variable "cap" for the
array, such that the upper limit would always be equal to the current
MaxPoint.

And if I set Point() to an insane cap like 2000000, I'll have to institute
a check prior to each write for null values of Point(T).[Structure
Members], just to minimize storage.

Hmm... It's enough to make me give a shot at understanding Serializeable
Classes

Thanks for your help,

The Confessor
Jan 7 '06 #3
Confessor,

Once you know the array size that you need you can use the REDIM command to
create an array of the appropriate size. Or you can use REDIM PRESERVE to
increase the array size as needed, while preserving the current elements.

Kerry Moorman
"Confessor" wrote:
"=?Utf-8?B?S2VycnkgTW9vcm1hbg==?="
<Ke**********@discussions.microsoft.com> wrote in
news:0E**********************************@microsof t.com:
I don't see where you have dimensioned your Point array to have any
elements.

So you can't refer to Point (MaxPoint), where MaxPoint is 1, since
there is no element 1 in the Point array.

Kerry Moorman


So,

---> Dim Point([any frickin' number]) As PointTemplate <---

will do it, eh? Makes sense. Don't recall having this problem in a previous
project, but I'd forgotten that I'd specifically dimensioned that
particular array to (85)

Rather discouraging, as I was planning on having a variable "cap" for the
array, such that the upper limit would always be equal to the current
MaxPoint.

And if I set Point() to an insane cap like 2000000, I'll have to institute
a check prior to each write for null values of Point(T).[Structure
Members], just to minimize storage.

Hmm... It's enough to make me give a shot at understanding Serializeable
Classes

Thanks for your help,

The Confessor

Jan 7 '06 #4
Mr. Moorman

I now have workable, if not exactly elegant, code... with a 38 Kilobyte
points.dat file that I can open and save at will to prove it.

Thank You,
The Confessor
"=?Utf-8?B?S2VycnkgTW9vcm1hbg==?="
<Ke**********@discussions.microsoft.com> wrote in
news:EA**********************************@microsof t.com:
Confessor,

Once you know the array size that you need you can use the REDIM
command to create an array of the appropriate size. Or you can use
REDIM PRESERVE to increase the array size as needed, while preserving
the current elements.

Kerry Moorman

Jan 7 '06 #5

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

Similar topics

1
by: Ian Barnes | last post by:
I have a VB6 program that uses standard ADO 2.5 connection to read and write to an Access 97 database on a Windows 98 machine. The same program is run by a number of other people who use Windows 98...
0
by: MarionEll | last post by:
XML Conference 2003 program now available…register with discounts now! IDEAlliance has just released the full program for XML 2003 scheduled December 7-12 at the Philadelphia Convention Center....
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
8
by: DraguVaso | last post by:
Hi, I had Visual Studio 2003 installed, and installed also visual Studio 2005 Beta 2. The problem is, when I am starting now (double click) a solution (*.sln-file), it always start it with...
7
by: Ottar | last post by:
I've made a program sorting incomming mail in public folder. The function runs every minute by using the form.timer event. In Access XP it runs for weeks, no problem. Access 2003 runs the same...
3
by: Lee Gillie | last post by:
I have a VS6 project which I brought into VS .NET, and all has been building fine. Then I upgraded to VS 2003 and I have one source which will no longer compile. Any clues? Compiling......
9
by: George McCullen | last post by:
I have an Outlook 2003 using Exchange Server 2003 Public Contacts Folder containing 20,000 Contacts. I am writing a VB .Net 2003 program that loops through all the contacts in a "for each oCt in...
5
by: cj | last post by:
In 2003 I had Public Class Form1 Inherits System.Windows.Forms.Form In 2005 I've seen it with and without the Inherits System.Windows.Forms.Form. Is it supposed to be there? I'm wondering...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.