-
August 26th, 2005, 09:03 AM
#1
Unable to set a property...
This is really odd. I went through this class with a debugger and after the constructor was called and the variables were assigned, the min and max were both -1 ? What am I screwing up?
Code:
Option Strict On
Option Explicit On
Public Class drawing_graph
Private max As Integer
Private min As Integer
Private difference As Integer
Private gr As graphics
Private point_keeper As ArrayList
Private d_panel As Panel
Public Property maximum() As Integer
Get
Return max
End Get
Set(ByVal Value As Integer)
If Value < Me.minimum Then
max = Me.minimum + 1
Exit Property
End If
max = Value
End Set
End Property
Public Property minimum() As Integer
Get
Return min
End Get
Set(ByVal Value As Integer)
If Value > Me.maximum Then
min = Me.maximum - 1
Exit Property
End If
min = Value
End Set
End Property
Private Property graphics() As graphics
Get
Return gr
End Get
Set(ByVal Value As graphics)
If Value Is Nothing Then
Throw New Exception("The passed in graphics was not allocated.")
Exit Property
End If
gr = Value
End Set
End Property
WriteOnly Property draw_panel() As Panel
Set(ByVal Value As Panel)
d_panel = Value
End Set
End Property
Sub New(ByVal gr As graphics, ByRef panel As Panel)
Try
Me.graphics = gr
Catch ex As Exception
MessageBox.Show(ex.Message, "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Try
Me.draw_panel = panel
Catch ex As Exception
MessageBox.Show(ex.Message, "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Me.maximum = 0
Me.minimum = 30
difference = Me.maximum - Me.minimum
End Sub
Public Sub draw(ByVal val As Integer)
If val > Me.maximum Then
val = Me.maximum
ElseIf val < Me.minimum Then
val = Me.minimum
End If
point_keeper.Add(val)
If point_keeper.Count = 30 Then
point_keeper.RemoveAt(point_keeper.Count - 1)
End If
clear()
sub_draw()
End Sub
Private Sub clear()
gr.Clear(Color.Azure)
End Sub
Private Sub sub_draw()
Const num_hlines As Double = 30.0
Dim line_points(point_keeper.Count) As Point
For i As Integer = 0 To point_keeper.Count
line_points(i) = New Point(CType(CType(d_panel.Width, Double) - _
((CType(d_panel.Width, Double) / num_hlines) * CType(i, Double)), Integer), _
CType(point_keeper(0), Integer))
Next
gr.DrawLines(Pens.Red, line_points)
End Sub
End Class
-
August 26th, 2005, 09:21 AM
#2
Re: Unable to set a property...
here's the problem,
these 2 lines in the constructor
will call the PROPERTY and not the data member
now you set max to 0 will go throug ok
Me.maximum = 0
but this
Me.minimum = 30
will get you inside your IF statement.
If Value > Me.maximum Then
min = Me.maximum - 1
Exit Property
End If
that's why you get -1
hope it helps
Nicolas Bohemier
-
August 26th, 2005, 09:39 AM
#3
Re: Unable to set a property...
That was a stupid mistake. Thanks.
-
August 26th, 2005, 09:52 AM
#4
Re: Unable to set a property...
hehe I guess you just inverted Max and min
Nicolas Bohemier
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|