473,508 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How in VB .NET to correct errors?

Hello. A problem in the following.
In VB .NET 2003 we create the project and in file Form1.vb the following
code is written down:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Create the data:
CreateData() 'Error
End Sub

'Create the data.
Private Sub CreateData()
'Axes X, Y, Z:
MakeSegment(0, 0, 0, 0.5, 0, 0) ' X axis. 'Error
MakeSegment(0, 0, 0, 0, 0.5, 0) ' Y axis.
MakeSegment(0, 0, 0, 0, 0, 0.5) ' Z axis.
End Sub

Public Structure Segment
'Connect the points:
<VBFixedArray(4)> Dim fr_pt() As Single
<VBFixedArray(4)> Dim to_pt() As Single
'Connect the transformed points:
<VBFixedArray(4)> Dim fr_tr() As Single
<VBFixedArray(4)> Dim to_tr() As Single
Public Sub Initialize()
ReDim fr_pt(4)
ReDim to_pt(4)
ReDim fr_tr(4)
ReDim to_tr(4)
End Sub
End Structure

Public Structure Transformation
<VBFixedArray(4, 4)> Dim M(,) As Single
Public Sub Initialize()
ReDim M(4, 4)
End Sub
End Structure

Public NumSegments As Short
Public Segments() As Segment

'Create a segment:
Public Sub MakeSegment(ByVal x1 As Single, ByVal y1 As Single, ByVal z1
As Single, _
ByVal x2 As Single, ByVal y2 As Single, ByVal z2
As Single)
NumSegments = NumSegments + 1
ReDim Preserve Segments(NumSegments)
Segments(NumSegments).fr_pt(1) = x1 'Error
Segments(NumSegments).fr_pt(2) = y1
Segments(NumSegments).fr_pt(3) = z1
Segments(NumSegments).fr_pt(4) = 1
Segments(NumSegments).to_pt(1) = x2
Segments(NumSegments).to_pt(2) = y2
Segments(NumSegments).to_pt(3) = z2
Segments(NumSegments).to_pt(4) = 1
End Sub

Building the project (Build, Build Solution) is carried out without errors.
However at running there are errors in the specified lines and the message:
Object reference not set to an instance of an object.

Inform, please, how to correct errors?

Beforehand many thanks for answer. Best regards, Dr. V.A. Zharkov. Moscow,
Russia.

Nov 20 '05 #1
13 2542
"Dr. Zharkov" <va************@mtu-net.ru> schrieb
Hello. A problem in the following.
In VB .NET 2003 we create the project and in file Form1.vb the
following code is written down:
I've already answerd in the other thread. Did you read it? Here it is again:
NumSegments = NumSegments + 1
ReDim Preserve Segments(NumSegments)
Segments(NumSegments).Initialize
Segments(NumSegments).fr_pt(1) = x1 'Error

This means that you have to call Sub Initialize for each Segment that you
create. If you don't call it, the fields within the structure (named fr_pt,
to_pt, fr_tr, to_tr) are Nothing. They are nothing because no array has been
assigned. The Redim statement within sub Initialize creates the arrays and
assigns them to the variables. If you don't call Initialize you get a
NullReferenceException.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Dear Mr. Armin Zingler.
Many thanks for your second answer (I have not had time to read your first
answer), which has allowed me to correct a error.
Excuse me, please, but I very much ask you to answer me the second question
on my second error.
In VB .NET 2003 we create the project, on the Form1 box place PictureBox1
and in file Form1.vb write the following code:

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

DrawData(PictureBox1)
End Sub
Private Sub DrawData(ByRef pic As Object)

DrawSomeData(pic)
End Sub
Private Sub DrawSomeData(ByVal pic As Object)

Dim redPen As New Pen(Color.Red, 3)
Dim g As Graphics = PictureBox1.CreateGraphics
g.DrawLine(redPen, 0, 0, 100, 200)
End Sub

Building the project (Build, Build Solution) is carried out without errors.
However at running on Form1 there is no line (g.DrawLine(redPen, 0, 0, 100,
200)).

Inform, please, how to construct a line inside PictureBox1 with the help of
Sub DrawSomeData?

Beforehand many thanks for answer. Best regards, Dr. V.A. Zharkov. Moscow,
Russia.

Nov 20 '05 #3
"Dr. Zharkov" <va************@mtu-net.ru> schrieb
In VB .NET 2003 we create the project, on the Form1 box place
PictureBox1 and in file Form1.vb write the following code:

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

DrawData(PictureBox1)
End Sub
Private Sub DrawData(ByRef pic As Object)

DrawSomeData(pic)
End Sub
Private Sub DrawSomeData(ByVal pic As Object)

Dim redPen As New Pen(Color.Red, 3)
Dim g As Graphics = PictureBox1.CreateGraphics
g.DrawLine(redPen, 0, 0, 100, 200)
End Sub

Building the project (Build, Build Solution) is carried out without
errors. However at running on Form1 there is no line
(g.DrawLine(redPen, 0, 0, 100, 200)).

Inform, please, how to construct a line inside PictureBox1 with the
help of Sub DrawSomeData?

You have to draw the line each time Windows asks you to draw it. This is
done in the Picturebox' paint event:

Private Sub PictureBox1_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles PictureBox1.Paint

e.graphics.DrawLine(Pens.Red, 0, 0, 100, 200)

End Sub

By the way, as the example shows, instead of creating a new red pen you can
use Pens.Red.

--
Armin

Nov 20 '05 #4
Dear Mr. Armin Zingler.
Many thanks for your answer. However your code is a usual code, which is
present in Help of VB .NET and which, naturally, to me is known.
Apparently, I could not formulate competently my question, therefore, if you
do not object, I'll try once again.
In VB .NET 2003 we create the project, on the Form1 box place PictureBox1
and in file Form1.vb write the following code:

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

DrawData(PictureBox1)
End Sub
Private Sub DrawData(ByRef pic As Object)

DrawSomeData(pic, 100, 200, _
System.Drawing.ColorTranslator.ToOle( _
System.Drawing.Color.Black), False)
End Sub
Public Sub DrawSomeData(ByVal pic As Object, _
ByVal first_seg As Short, ByVal last_seg As Short, _
ByVal myColor As Integer, ByVal clear As Boolean)

Dim redPen As New Pen(Color.Red, 3)
Dim g As Graphics = PictureBox1.CreateGraphics

g.DrawLine(redPen, 0, 0, first_seg, last_seg)
End Sub

Building the project (Build, Build Solution) is carried out without errors.
However at running on PictureBox1 there is no line (g.DrawLine(redPen, 0, 0,
first_seg, last_seg)
Inform, please, how to change the procedure Sub DrawSomeData, that this
procedure Sub DrawSomeData built a line (g.DrawLine(redPen, 0, 0, first_seg,
last_seg)) inside PictureBox1?

Beforehand many thanks for answer. Best regards, Dr. V.A. Zharkov. Moscow,
Russia.


Nov 20 '05 #5
"Dr. Zharkov" <va************@mtu-net.ru> schrieb
Dear Mr. Armin Zingler.
Dear Dr. Zharkov,

if you don't mind you can simply call me "Armin" because this is common
usage in the usenet, but of course you don't have to. :-)
Many thanks for your answer. However your code is a usual code, which
is present in Help of VB .NET and which, naturally, to me is
known. Apparently, I could not formulate competently my question,
therefore, if you do not object, I'll try once again.

In VB .NET 2003 we create the project, on the Form1 box place
PictureBox1 and in file Form1.vb write the following code:

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

DrawData(PictureBox1)
End Sub
Private Sub DrawData(ByRef pic As Object)

DrawSomeData(pic, 100, 200, _
System.Drawing.ColorTranslator.ToOle( _
System.Drawing.Color.Black), False)
End Sub
Public Sub DrawSomeData(ByVal pic As Object, _
ByVal first_seg As Short, ByVal last_seg As Short, _
ByVal myColor As Integer, ByVal clear As Boolean)

Dim redPen As New Pen(Color.Red, 3)
Dim g As Graphics = PictureBox1.CreateGraphics

g.DrawLine(redPen, 0, 0, first_seg, last_seg)
End Sub

Building the project (Build, Build Solution) is carried out without
errors. However at running on PictureBox1 there is no line
(g.DrawLine(redPen, 0, 0, first_seg, last_seg)
Inform, please, how to change the procedure Sub DrawSomeData, that
this procedure Sub DrawSomeData built a line (g.DrawLine(redPen, 0,
0, first_seg, last_seg)) inside PictureBox1?

Beforehand many thanks for answer. Best regards, Dr. V.A. Zharkov.
Moscow, Russia.


You formulated your question very well. I do understand what is your
concern. After reading your question again, I still understand it the same
way.

What I was trying to say in my previous post: You have to draw the line in
the Paint event of the Picturebox. You can not draw the line on the
picturebox in Form1_Load because the Form is not yet visible in Form_Load.
It is also not sufficient to draw the line one time, you have to draw it
each time when Windows wants you to draw it. The background is the
following: Imagine you draw the line on a visible picturebox. Then you
switch to a different applicatoin. The program covers your first
application. Then you switch back to the application. The Form and the
picturebox becomes visible again. In this case, Windows requests you to draw
the line *again* because the content of the screen has been overwritten by
the other application meanwhile. In other words: Graphics you draw on the
screen are not persistent. Windows does not remember the graphics you
painted. The graphics have to be drawn each time the part of the screen
becomes visible. Windows knows which window has to be redrawn and sents a
message to the window. Each time you get the message, the Paint event of the
picturebox is raised. That is the place where you can draw the graphics
again. Otherwise the window remains empty.

Additionally: A Picturebox has the property "Image". When you have assigned
an image to this property, the picturebox automatically draws the image
whenever Windows requests the picturebox to paint it's content. Therefore,
instead of manually painting the content of the Picturebox in it's Paint
event, you can assign an Image to the picturebox. Now you can ignore the
Paint event, but you have to draw on the Image instead. The advantage is
that you can draw before the picturebox is visible. You could create a
Bitmap in Form_Load, draw on the Bitmap and assign the Bitmap to the
Picturebox' Image property. Here is an example:

private m_Bitmap As Bitmap

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

m_Bitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
DrawData(m_Bitmap)
End Sub

Public Sub DrawData(ByVal img As Image)

Dim g As Graphics = graphics.Fromimage(img)

g.DrawLine(Pens.Red, 0, 0, 100, 200)
g.Dispose
End Sub
If you have any questions, don't hesitate to ask again. :-)
If you are interested in more information about message queues (messages
like WM_PAINT sent by Windows to your application):

http://msdn.microsoft.com/library/en...sagequeues.asp

About painting and drawing, expecially sub topic "Using the WM_PAINT message":
http://msdn.microsoft.com/library/en...tdraw_3wtj.asp
--
Armin

Nov 20 '05 #6
Cor
Armin,

Excelent

While reading it I thought: "Why not in that way and you did explain it how
to do that, exactly as I thougth that was the alternative".

Cor
Nov 20 '05 #7
"Cor" <no*@non.com> schrieb
Armin,

Excelent

While reading it I thought: "Why not in that way and you did explain
it how to do that, exactly as I thougth that was the alternative".


I don't understand you.
--
Armin

Nov 20 '05 #8
Cor
Armin,

I found your explanation very good.

There was a part in where you said, why not converting it to an image, so
you don't have to paint it everytime. That idea I got while reading your
explanation.

But even that you wrote therefore my compliments, that is all.

Cor
Nov 20 '05 #9
"Cor" <no*@non.com> schrieb
There was a part in where you said, why not converting it to an
image, so you don't have to paint it everytime.
I did not write to *convert* it to an image.
That idea I got
while reading your explanation.

But even that you wrote therefore my compliments, that is all.


Thx

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #10
Hello Armin.
Many thanks for your very detailed both very much qualified answer and your
kind consent to answer other my questions. At me to you the following
request.
From one site to me have sent on email the project for VB6 on 3D-graphics.
In this project in three-dimensional measurement are drawn and rotate some
geometrical figures (a cube, a pyramid and others). On my computer is not
present VB6, and is VB .NET 2003. I standartly converted project VB6 in VB
..NET 2003, has corrected some errors (now building this project "Build,
Build Solution" is carried out without errors), but I can not debug it (this
project does not draw the figures). And all my previous questions to you
concern debugging this project.

At me to you the big request, Armin. It is possible for me to send you on
email this project for VB6, to ask you to convert it on VB .NET (or on VB
..NET 2003) and to ask you to inform me, how to start this project on VB .NET
2003?

Beforehand many thanks for answer. Best regards, Dr. V.A. Zharkov. Moscow,
Russia.

Nov 20 '05 #11
"Dr. Zharkov" <va************@mtu-net.ru> schrieb
Hello Armin.
Many thanks for your very detailed both very much qualified answer
and your kind consent to answer other my questions. At me to you
the following request.
From one site to me have sent on email the project for VB6 on
3D-graphics. In this project in three-dimensional measurement are
drawn and rotate some geometrical figures (a cube, a pyramid and
others). On my computer is not present VB6, and is VB .NET 2003. I
standartly converted project VB6 in VB .NET 2003, has corrected
some errors (now building this project "Build, Build Solution" is
carried out without errors), but I can not debug it (this project
does not draw the figures). And all my previous questions to you
concern debugging this project.

At me to you the big request, Armin. It is possible for me to send
you on email this project for VB6, to ask you to convert it on VB
.NET (or on VB .NET 2003) and to ask you to inform me, how to
start this project on VB .NET 2003?

Beforehand many thanks for answer. Best regards, Dr. V.A. Zharkov.
Moscow, Russia.


You can send the project to me. (ZIP format please; do *not* remove "nospam"
from my mail address) Better: If possible, copy the file to an FTP server
and post the link here, so everyone interested in can download it.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #12
Hello Armin.
Many thanks for your kind consent to consider the project for VB6.
Now I have sent the letter to the address, specified by you; answer, please,
it.
Here I will take advantage of your kind permission to set to you questions.
The code, specified by you, does not draw a line:

private m_Bitmap As Bitmap

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

m_Bitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
DrawData(m_Bitmap)
End Sub

Public Sub DrawData(ByVal img As Image)

Dim g As Graphics = graphics.Fromimage(img)

g.DrawLine(Pens.Red, 0, 0, 100, 200)
g.Dispose
End Sub

Inform, please, where in this code an error?

Beforehand many thanks for your answer. Best regards, Dr. V.A. Zharkov.

Nov 20 '05 #13
"Dr. Zharkov" <va************@mtu-net.ru> schrieb
Hello Armin.
Many thanks for your kind consent to consider the project for VB6.
Now I have sent the letter to the address, specified by you; answer,
please, it.
I received the mail but it has no attachment.
Here I will take advantage of your kind permission to set to you
questions. The code, specified by you, does not draw a line:

private m_Bitmap As Bitmap

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

m_Bitmap = New Bitmap(PictureBox1.Width,
PictureBox1.Height) DrawData(m_Bitmap)
End Sub

Public Sub DrawData(ByVal img As Image)

Dim g As Graphics = graphics.Fromimage(img)

g.DrawLine(Pens.Red, 0, 0, 100, 200)
g.Dispose
End Sub

Inform, please, where in this code an error?

You did not assign the Bitmap to the Image property of the Picturebox:

Me.Picturebox1.Image = m_Bitmap
--
Armin

Nov 20 '05 #14

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

Similar topics

1
3320
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
0
1005
by: ST | last post by:
Hello, I will be posting 2 errors that I just can't seem to figure out (I'll put them in different posts). I have looked all over the internet, and I still can't figure these out! This webapp was...
14
2125
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
53
4501
by: Alf P. Steinbach | last post by:
So, I got the itch to write something more... I apologize for not doing more on the attempted "Correct C++ Tutorial" earlier, but there were reasons. This is an UNFINISHED and RAW document,...
102
5571
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
1
320
by: Dr. Zharkov | last post by:
Hello. A problem in the following. In VB .NET 2003 I create the project and in file Form1.vb is written down the following code: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As...
0
3106
by: bnlockwood | last post by:
G'day all, Thank you in advance for anyone that can help. I have a shopping cart datagrid on my c# asp.net page. This is the code: ------------------------------------- <asp:datagrid...
6
1473
by: VMI | last post by:
What's the correct way of using try...catch in my web application? For example, if I catch a connection error or something with the DB, how am I supposed to bubble it up to the web interface? Is...
0
141
by: Luis Zarrabeitia | last post by:
Quoting Christian Heimes <lists@cheimes.de>: Weird, I can't find neither... (which wikipedia article? Couldn't find one about C99.) Don't take me wrong, I believe you... but I would really...
6
2848
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
0
7223
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,...
0
7115
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
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
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...
1
7036
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
7489
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
4705
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...
0
3191
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...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.