|
-
Sep 2nd, 2010, 06:13 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Enum property changing unexpectedly
Hi,
I have an Enum file, as shown in first code block. Though it's first time I use an enum file, so maybe it's not correct to use it like this.. My purpose is just to be able to reference a global parameter from anywhere, so I can just type DataInterval.M1, and it will be treated as an integer... or.. will it not ?
Further I have a property in my DataSeries class, of type DataInterval. And in this class I also have a bunch of methods Get/Set etc. to do different work on the dataseries (Inherits List(Of BarData)).
Problem: The interval property keeps changing unexpectedly every time the GetNextCloseTime function is called.
So what am I doing wrong here.... ? Any other critic is also much welcomed!

Code:
''' <summary>
''' "Time Frame" of data series
''' </summary>
''' <remarks></remarks>
Public Enum DataInterval
M1 = 1
M2 = 2
M3 = 3
M5 = 5
M10 = 10
M13 = 13
M15 = 15
M30 = 30
M60 = 60
M120 = 120
M240 = 240
D = 101
W = 102
M = 103
End Enum
Code:
<Serializable()> Public Class DataSeries
Inherits List(Of BarData)
Private _Interval As New DataInterval
Private Property Interval() As DataInterval
Get
Return _Interval
End Get
Set(ByVal value As DataInterval)
_Interval = value
End Set
End Property
' ................
Public Sub UpdateBarByTick(ByVal tickTime As Date, ByVal price As Double)
Dim newBar As BarData
If IsDataSeriesEmpty() Or IsTimeAfterCurrentBarCloseTime(tickTime) Then
newBar = New BarData(GetNextCloseTime, price, price, price, price, 0)
Me.AddBar(newBar)
Else
Dim currentBarUpdate As New BarData
currentBarUpdate = GetLastBar()
currentBarUpdate.Close = price
' Set new High/Low if occur
If price > currentBarUpdate.High Then
currentBarUpdate.High = price
ElseIf price < currentBarUpdate.Low Then
currentBarUpdate.Low = price
End If
UpdateBarIndex(Me.Count - 1, currentBarUpdate)
End If
RaiseEvent TickUpdate(GetLastBar)
End Sub
' ................
Public Function GetNextCloseTime() As Date
Dim intervalTimeSpan As New TimeSpan(0, Me.Interval, 0)
Dim currentCloseInMinutes As Integer
currentCloseInMinutes = Fix(Date.Now.Minute / Me.Interval) * Me.Interval
Dim nextCloseTime As New Date(Date.Now.Year, Date.Now.Month, Date.Now.Day, Date.Now.Hour, currentCloseInMinutes, 0)
nextCloseTime = nextCloseTime + intervalTimeSpan
Return nextCloseTime
End Function
-
Sep 2nd, 2010, 06:22 PM
#2
Re: Enum property changing unexpectedly
When things are changing unexpectedly, it's because there's something usually going on that has been overlooked or misunderstood. What I would do is put a watch on _Interval, then set it to Break When Value Changes. Then anytime something changes the variable, it will stop. You can then check the call stack and see where/why it is being changed.
-tg
-
Sep 2nd, 2010, 07:39 PM
#3
Thread Starter
Addicted Member
Re: Enum property changing unexpectedly
Thanks! I didn't know about the call stack. Gosh.. I been missing that..
However, in this case the property itself is not changing. As I have set a breakpoint on the property Set method, and it doesn't visit it. Still, when I debug.print Me.Interval, i get different values over and over. It gives me other values from the Enum list, although the property has not been changed through it's set method..
This is from debug.print inside GetNextCloseTime function:
http://i51.tinypic.com/10zpnjp.png
So I feel quite certain i'm using the enum stuff wrong, i just don't know what is happening.
-
Sep 2nd, 2010, 08:06 PM
#4
Re: Enum property changing unexpectedly
this might be it...
Private _Interval As New DataInterval
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 2nd, 2010, 08:26 PM
#5
Thread Starter
Addicted Member
Re: Enum property changing unexpectedly
 Originally Posted by .paul.
this might be it...
Private _Interval As New DataInterval
hmm.. No, That didn't help/change anything.
Last edited by bretddog; Sep 3rd, 2010 at 02:40 AM.
-
Sep 3rd, 2010, 05:19 AM
#6
Thread Starter
Addicted Member
Re: Enum property changing unexpectedly
Ok, solved..
I thought I only referenced one dataseries, but I was looping through a list of them. Hence property was from different instances... Duh... 
cheers!
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
|