473,408 Members | 1,775 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,408 software developers and data experts.

Object reference not set to an instance of an object.

I am trying to draw line.....Actually these codes were previously in vb 6...i tried to change them in vb.net....but every time i try to run the application i got this error ."Object reference not set to an instance of an object"...plz help me regerding this error....here are my code

Expand|Select|Wrap|Line Numbers
  1. Sub BeamDraw(ByRef DrawControl As PaintEventArgs, ByRef ds As DAO.Recordset)
  2.         Dim Y5 As Double
  3.         Dim X5 As Double
  4.         Dim Y2 As Double
  5.         Dim X2 As Double
  6.         Dim Y3 As Double
  7.         Dim X3 As Double
  8.         Dim Y1 As Double
  9.         Dim X1 As Double
  10.         Dim szcolumn As String
  11.         Dim X As Single
  12.         Dim Y As Single
  13.         Dim Dc As DAO.Recordset
  14.         Dim DCC As DAO.Recordset
  15.         DCC = CurDb.OpenRecordset("Columns", DAO.RecordsetTypeEnum.dbOpenDynaset)
  16.         Dc = CurDb.OpenRecordset("Columns", DAO.RecordsetTypeEnum.dbOpenDynaset)
  17.         While Not ds.EOF
  18.             szcolumn = "Cname='" + ds.Fields(0).Value + "'"
  19.             DCC.FindFirst(szcolumn)
  20.             X = DCC.Fields(4).Value
  21.             Y = DCC.Fields(5).Value
  22.             X1 = DCC.Fields(4).Value
  23.             Y1 = DCC.Fields(5).Value
  24.             FlushDistances(DCC, X, Y)
  25.             X3 = X
  26.             Y3 = Y
  27.             If StrComp(Left(DCC.Fields(0).Value, 1), "C") = 0 Then
  28.                 Select Case DCC.Fields(1).Value
  29.                     Case "H"
  30.                         DrawControl.Graphics.DrawLine(Pens.OrangeRed, CInt(X - DCC.Fields(2).Value / 2), CInt(Y - DCC.Fields(3).Value / 2) - CInt(X + DCC.Fields(2).Value / 2), CInt(Y + DCC.Fields(3).Value / 2), B)
  31.  
  32.  
  33.                 End Select
  34.             Else
  35.                 Select Case DCC.Fields(1).Value
  36.                     Case "H"              
  37.                         DrawControl.Graphics.DrawLine(Pens.OrangeRed, CInt(X - DCC.Fields(2).Value / 2), CInt(Y - DCC.Fields(3).Value / 2) - CInt(X + DCC.Fields(2).Value / 2), CInt(Y + DCC.Fields(3).Value / 2), B)
  38.  
  39.                 End Select
  40.             End If
  41.             If Enlarge Or BeamSelect Then
  42.                 Column_Dis(DCC.Fields(4).Value + DCC.Fields(2).Value / 2, DCC.Fields(5).Value - DCC.Fields(3).Value / 2, DCC.Fields(0).Value, DrawControl)
  43.             End If
  44.             szcolumn = "Cname='" + ds.Fields(1).Value + "'"
  45.             Dc.FindFirst(szcolumn)
  46.             X = (Dc.Fields(4).Value)
  47.             Y = (Dc.Fields(5).Value)
  48.             X2 = Dc.Fields(4).Value
  49.             Y2 = Dc.Fields(5).Value
  50.             FlushDistances(Dc, X, Y)
  51.             X5 = X
  52.             Y5 = Y
  53.             If X1 = X2 Then
  54.                 CenterFlag = "BeamVertical"
  55.             Else
  56.                 If Y1 = Y2 Then
  57.                     CenterFlag = "BeamHorizontal"
  58.                 End If
  59.             End If
  60.             If StrComp(Left(Dc.Fields(0).Value, 1), "C") = 0 Then
  61.                 Select Case Dc.Fields(1).Value
  62.                     Case "H"
  63.                         DrawControl.Graphics.DrawLine(Pens.OrangeRed, CInt(X - Dc.Fields(2).Value / 2), CInt(Y - Dc.Fields(3).Value / 2), CInt(X + Dc.Fields(2).Value / 2), CInt(Y + Dc.Fields(3).Value / 2))
  64.  
  65.                 End Select
  66.             Else
  67.                 Select Case Dc.Fields(1).Value
  68.                     Case "H"
  69.  
  70.                         DrawControl.Graphics.DrawLine(Pens.OrangeRed, CInt(X - Dc.Fields(2).Value / 2), CInt(Y - Dc.Fields(3).Value / 2) - CInt(X + Dc.Fields(2).Value / 2), CInt(Y + Dc.Fields(3).Value / 2), B)
  71.  
  72.                 End Select
  73.             End If
  74.  
  75.             If Enlarge Or BeamSelect Then
  76.                 Column_Dis(Dc.Fields(4).Value + Dc.Fields(2).Value / 2, Dc.Fields(5).Value - Dc.Fields(3).Value / 2, Dc.Fields(0).Value, DrawControl)
  77.             End If
  78.             ShowBeam(ds, DCC, DCC, DrawControl, X3, Y3, X5, Y5, CenterFlag)
  79.             ds.MoveNext()
  80.         End While
  81.     End Sub
Oct 22 '08 #1
5 1212
kenobewan
4,871 Expert 4TB
It would help if you could provide more information. Do you have a line number where it is occurring or can you trap it?
Oct 22 '08 #2
Well thanks for replying........Actually in my project i have 2 forms one consist of a datagrid and other form consisting of a picture box,,,,,and now when you enter data in first form you can see the drawing of your data in the other form.

also i am using vb.net for first time so if u can help me what should i use for drawing lines ...... system.drawing.graphics or system.windows.forms.paintEventargs
Oct 23 '08 #3
tlhintoq
3,525 Expert 2GB
I am trying to draw line.....Actually these codes were previously in vb 6...i tried to change them in vb.net....but every time i try to run the application i got this error ."Object reference not set to an instance of an object"...plz help me regerding this error....here are my code

Expand|Select|Wrap|Line Numbers
  1. Sub BeamDraw(ByRef DrawControl As PaintEventArgs, ByRef ds As DAO.Recordset)
  2.         Dim Y5 As Double
  3.         Dim X5 As Double
  4.         Dim Y2 As Double
  5.         Dim X2 As Double
  6.         Dim Y3 As Double
  7.         Dim X3 As Double
  8.         Dim Y1 As Double
  9.         Dim X1 As Double
  10.         Dim szcolumn As String
  11.         Dim X As Single
  12.         Dim Y As Single
  13.         Dim Dc As DAO.Recordset
  14.         Dim DCC As DAO.Recordset
  15.         DCC = CurDb.OpenRecordset("Columns", DAO.RecordsetTypeEnum.dbOpenDynaset)
  16.         Dc = CurDb.OpenRecordset("Columns", DAO.RecordsetTypeEnum.dbOpenDynaset)
  17.         While Not ds.EOF
  18.             szcolumn = "Cname='" + ds.Fields(0).Value + "'"
  19.             DCC.FindFirst(szcolumn)
  20.             X = DCC.Fields(4).Value
  21.             Y = DCC.Fields(5).Value
  22.             X1 = DCC.Fields(4).Value
  23.             Y1 = DCC.Fields(5).Value
  24.             FlushDistances(DCC, X, Y)
  25.             X3 = X
  26.             Y3 = Y
  27.             If StrComp(Left(DCC.Fields(0).Value, 1), "C") = 0 Then
  28.                 Select Case DCC.Fields(1).Value
  29.                     Case "H"
  30.                         DrawControl.Graphics.DrawLine(Pens.OrangeRed, CInt(X - DCC.Fields(2).Value / 2), CInt(Y - DCC.Fields(3).Value / 2) - CInt(X + DCC.Fields(2).Value / 2), CInt(Y + DCC.Fields(3).Value / 2), B)
  31.  
  32.  
  33.                 End Select
  34.             Else
  35.                 Select Case DCC.Fields(1).Value
  36.                     Case "H"              
  37.                         DrawControl.Graphics.DrawLine(Pens.OrangeRed, CInt(X - DCC.Fields(2).Value / 2), CInt(Y - DCC.Fields(3).Value / 2) - CInt(X + DCC.Fields(2).Value / 2), CInt(Y + DCC.Fields(3).Value / 2), B)
  38.  
  39.                 End Select
  40.             End If
  41.             If Enlarge Or BeamSelect Then
  42.                 Column_Dis(DCC.Fields(4).Value + DCC.Fields(2).Value / 2, DCC.Fields(5).Value - DCC.Fields(3).Value / 2, DCC.Fields(0).Value, DrawControl)
  43.             End If
  44.             szcolumn = "Cname='" + ds.Fields(1).Value + "'"
  45.             Dc.FindFirst(szcolumn)
  46.             X = (Dc.Fields(4).Value)
  47.             Y = (Dc.Fields(5).Value)
  48.             X2 = Dc.Fields(4).Value
  49.             Y2 = Dc.Fields(5).Value
  50.             FlushDistances(Dc, X, Y)
  51.             X5 = X
  52.             Y5 = Y
  53.             If X1 = X2 Then
  54.                 CenterFlag = "BeamVertical"
  55.             Else
  56.                 If Y1 = Y2 Then
  57.                     CenterFlag = "BeamHorizontal"
  58.                 End If
  59.             End If
  60.             If StrComp(Left(Dc.Fields(0).Value, 1), "C") = 0 Then
  61.                 Select Case Dc.Fields(1).Value
  62.                     Case "H"
  63.                         DrawControl.Graphics.DrawLine(Pens.OrangeRed, CInt(X - Dc.Fields(2).Value / 2), CInt(Y - Dc.Fields(3).Value / 2), CInt(X + Dc.Fields(2).Value / 2), CInt(Y + Dc.Fields(3).Value / 2))
  64.  
  65.                 End Select
  66.             Else
  67.                 Select Case Dc.Fields(1).Value
  68.                     Case "H"
  69.  
  70.                         DrawControl.Graphics.DrawLine(Pens.OrangeRed, CInt(X - Dc.Fields(2).Value / 2), CInt(Y - Dc.Fields(3).Value / 2) - CInt(X + Dc.Fields(2).Value / 2), CInt(Y + Dc.Fields(3).Value / 2), B)
  71.  
  72.                 End Select
  73.             End If
  74.  
  75.             If Enlarge Or BeamSelect Then
  76.                 Column_Dis(Dc.Fields(4).Value + Dc.Fields(2).Value / 2, Dc.Fields(5).Value - Dc.Fields(3).Value / 2, Dc.Fields(0).Value, DrawControl)
  77.             End If
  78.             ShowBeam(ds, DCC, DCC, DrawControl, X3, Y3, X5, Y5, CenterFlag)
  79.             ds.MoveNext()
  80.         End While
  81.     End Sub
Total stab in the dark by someone who doesn't do VB...

In line 78 you make use of CenterFlag variable.
I see no place where you create this variable (Looks like that is done with the DIM statement as in line 10 ??)

Assuming this is a global variable created elsewhere... Is it ever initialized to a default value? CenterFlag only gets set in Verticle in line 54 if X1=X2 or to Horizontal in line 57 if Y1=Y2. What happens if neither of these conditions exist? Does CenterFlag remain unset later when it is used in line 78?
Oct 23 '08 #4
r035198x
13,262 8TB
Well thanks for replying........Actually in my project i have 2 forms one consist of a datagrid and other form consisting of a picture box,,,,,and now when you enter data in first form you can see the drawing of your data in the other form.

also i am using vb.net for first time so if u can help me what should i use for drawing lines ...... system.drawing.graphics or system.windows.forms.paintEventargs
Why don't you just tell us the number reported for that exception?
Oct 23 '08 #5
Total stab in the dark by someone who doesn't do VB...

In line 78 you make use of CenterFlag variable.
I see no place where you create this variable (Looks like that is done with the DIM statement as in line 10 ??)

Assuming this is a global variable created elsewhere... Is it ever initialized to a default value? CenterFlag only gets set in Verticle in line 54 if X1=X2 or to Horizontal in line 57 if Y1=Y2. What happens if neither of these conditions exist? Does CenterFlag remain unset later when it is used in line 78?
Then it Will give us a diagonal Connection....Well Thank u .....
Oct 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
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...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
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...
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 { /*
14
by: Philipp Reif | last post by:
Hi all, I've got a little hole in my head concerning references. Here's what I'm trying to do: I'm calling a function, passing the reference of a business object for editing. The function clones...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
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);
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
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
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
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
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
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...
0
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...

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.