Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

VB.NET

 

I am trying to draw lines on my form.

 

I have a class called LineStuff and in the declarations at the top I am calling it:

 

Public mylines(999) As LineStuff

Public newestline as integer = 0

 

As a test I simply have form load setting the properties of mylines(newestline).X1 ,x2,y1,y2 etc.. At current in app newest line is always 0 I haven't added the step up yet.

 

Then I have the form Paint procedure.

 

With

 

 

'---------------

 

 

Dim g As Graphics = e.Graphics

Dim q As Integer = 0

Dim mypen As New Pen(Color.Black, 1)

mylines(q) = New LineStuff

 

 

 

 

 

Do

If mylines(q).X1 = 0 Or mylines(q).X2 = 0 Or mylines(q).Y1 = 0 Or mylines(q).Y2 = 0 Then Exit Do

 

g.DrawLine(mypen, mylines(q).X1, mylines(q).Y1, mylines(q).X2, mylines(q).Y2)

If newestline = 0 Then

Exit Do

Else

q += 1

End If

 

Loop Until q > newestline

 

 

When I run it, it gets to the paint event through a timer [[invalidate()]] but will not access the class.

 

When it tries to access mylines it says.

 

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication2.exe

 

Additional information: Object reference not set to an instance of an object.

 

Does anybody have any suggestions. I am just now switching from VB6 to .NET

  • Administrators
Posted

you could change the line

 
mylines(q) = New LineStuff

 

to something like

dim i as interger
for i = 0 to 999
   mylines(i) = new LineStuff
next

 

this would pre-create all 1000 items. This may be a bit heavy on memory unless you knew that you would always need 1000 items in the array.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...