Page 1 of 1

Quick .NET beginner question.. accessing series

Posted: Thu Jun 01, 2006 5:27 pm
by 9641209
I have a quick question. Sorry if this is a basic one, but I'm new to .NET and fully object oriented programming.

I've been using VB6 with Teechart (activeX) since version 4 all the way to 7, and never had problems with it. Having recently moved to .NET and the new object model (using with VB.NET now), I have a question.

My application manipulates the chart by means of buttons that generate/delete series.

I seem to have some trouble accessing series defined by one button when I try to reach them in subroutines
controlling other buttons.


What I am doing is:


1) I define, say, 3 series at the public level of the class. (a candle and, say, 2 line series). I expected that to make those series public to all routines in that class, no?

2) Then, with a button, I generate a new instance of the candle series, and read data into it.

3) Next, with another button, I could generates a channel establishing a margin of confidence with upper and lower exponential moving averages. For that I generate two new instances of the line series and try to access the values of the candle series defined in button of step 2.

That's when I notice that I the candle series is set to nothing, ie. can't be seen, if I refer to it by name. I can probably access it if I refer to it by tchart.series(number)... Is there a way to share the object directly using some public reference for that class? Since these are controlled by buttons, I don't think I can add the names as parameters to the button handle.. or can I?

It's probably very simple, and my due to own ignorance. I tried to structure my question more clearly below.


Many thanks for any insight.

JET



Public Class frmchannel

'***** step 1 defining the public objects *****

Public mychannelcandle As TeeChart.Styles.Candle
Public mychannelrateupperline As TeeChart.Styles.Line
Public mychannelratelowerline As TeeChart.Styles.Line
.
.
.

(etc... code)


private sub button1toreloadcandlechart (.....)
.
.
.
'***** step 2 - new instance of the candle series and later in the code feeding it data

Dim mychannelcandle As New TeeChart.Styles.Candle(TChartchannel.Chart)
.
. (more code feeding data into the candle and displaying it)
.
end sub



private sub button2togeneratechannel (....)
.
.
.
'**** step 3 - new instances of the 2 line series and later on trying to access the mychannelcandle from this routine, using me.mychannelcandle, I run into problems.
'**** Can only access it if I refer to tchart.series(0), or similar.. is it the only way to do it, or is there a way to access the series by names directly?

Dim mymovingaveragechannelexpline1line As New TeeChart.Styles.FastLine(TChartchannel.Chart)
Dim mymovingaveragechannelexpline2line As New TeeChart.Styles.FastLine(TChartchannel.Chart)
.
.(more code where I try to access me.mychannelcandle from step 2 and have problems)
.

end sub

end class

Posted: Fri Jun 02, 2006 7:39 am
by narcis
Hi thomaz,

The problem is because you need to declare the series instances as shown in the example below. Also, there's no need to declare series being public. For more information please have a look at Access Levels in Visual Basic.

Code: Select all

Imports Steema

Public Class Form1
    Private mychannelcandle As TeeChart.Styles.Candle

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.mychannelcandle = New TeeChart.Styles.Candle(TChart1.Chart)
        Me.mychannelcandle.FillSampleValues()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.mychannelcandle.Clear()
    End Sub
End Class