drawing lines

R

Ranjit

Please tell me why the line is not been displayed on my
form.This code of mine contains absolutely no errors but
the lines are not being displayed on my form.Here is my
coding.I'm actually forced to put this in newsgroup since
I'm the only person who knows atleast a bit about VB.net
in my company and many of my friends dont know VB.net.So
I'm helpless.Here's my coding :

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
On Error Resume Next
For i = 0 To rs.RecordCount
x1 = Val(CStr(rs.Fields("Easting").Value))
y1 = Val(CStr(rs.Fields("Northing").Value))
Dim pt As Point = New Point(x1, y1)
Dim pt2 As Point = New Point(x2, y2)
e.Graphics.DrawLine(Pens.Green, myconversion
(pt), myconversion(pt2))
rs.MoveNext()
x2 = Val(CStr(rs.Fields("Easting").Value))
y2 = Val(CStr(rs.Fields("Northing").Value))
e.Graphics.DrawLine(Pens.Green, myconversion
(pt), myconversion(pt2))
Next
rs.Close()
End Sub

Private Function myconversion(ByVal temp As Point) As
Point
Return New Point(temp.X, Me.ClientSize.Height -
temp.Y)
End Function


It contains no error but the lines are not been shown and
I did connect it to my Access database properly.There are
about atleast 120 records in my Access database.

Thanking You,
Ranjit
 
I

IbrahimMalluf

Hello Ranjit

1. if you remove the "On Error Resume Next" line, you code will immediatly
bomb out. So the statement that there are no errors is not accurate

2. The 'RS' is not declared so what it is is not exactly clear. But the
methods you are associating with it indicate that it is a ADO COM style
recordset. Get away from it and use ADO.NET instead. Life will be much
better once you do.

3. the code below is a simplification of your code using a for/next loop.
It draws a green line diagonally accross the form. so your code basically
works. Make sure you have data in that recordset you are using.



--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx

Dim Icount As Integer

Dim X1 As Integer

Dim X2 As Integer

Dim Y1 As Integer

Dim Y2 As Integer

Dim PT As Point

Dim PT2 As Point

For Icount = 0 To 2500 Step +20

X1 = Icount

Y1 = Icount

PT = New Point(X1, Y1)

e.Graphics.DrawLine(Pens.Green, Me.myconversion(PT), Me.myconversion(PT2))

X2 = Icount

Y2 = Icount

e.Graphics.DrawLine(Pens.Green, Me.myconversion(PT), Me.myconversion(PT2))

Next

Private Function myconversion(ByVal temp As Point) As Point

Return New Point(temp.X, Me.ClientSize.Height - temp.Y)

End Function
 
H

Herfried K. Wagner [MVP]

* "Ranjit said:
Please tell me why the line is not been displayed on my
form.This code of mine contains absolutely no errors but
the lines are not being displayed on my form.Here is my
coding.I'm actually forced to put this in newsgroup since
I'm the only person who knows atleast a bit about VB.net
in my company and many of my friends dont know VB.net.So
I'm helpless.Here's my coding :

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
On Error Resume Next

No wonder that there are no errors if you "eat" them... Remove the line
above and try again.
For i = 0 To rs.RecordCount

Where did you declare 'i', where 'rs'? Enable 'Option Strict On' and
'Option Explicit On' (see MSDN).
x1 = Val(CStr(rs.Fields("Easting").Value))
y1 = Val(CStr(rs.Fields("Northing").Value))

Are you sure the right values are returned?
Dim pt As Point = New Point(x1, y1)
Dim pt2 As Point = New Point(x2, y2)
e.Graphics.DrawLine(Pens.Green, myconversion
(pt), myconversion(pt2))
rs.MoveNext()
x2 = Val(CStr(rs.Fields("Easting").Value))
y2 = Val(CStr(rs.Fields("Northing").Value))
e.Graphics.DrawLine(Pens.Green, myconversion
(pt), myconversion(pt2))
Next
rs.Close()

You always close the recordset. This doesn't make sense.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top