Results 1 to 6 of 6

Thread: [RESOLVED] Enum property changing unexpectedly

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    185

    Resolved [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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    185

    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.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Enum property changing unexpectedly

    this might be it...

    Private _Interval As New DataInterval

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    185

    Re: Enum property changing unexpectedly

    Quote Originally Posted by .paul. View Post
    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    185

    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
  •  



Click Here to Expand Forum to Full Width