Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I create instances of CWxxx objects?

I don't know if what I am try to do is possible, but I would like to create instances of a couple CW objects/collections.
I would optimally like to create an instance of a CWPlots object in VB and modify it programmatically so that I can set the CWPlots object directly in a CWGraph (or each CWPlot).
I am trying to create an array consisting of elements that contain a CWPlots and CWAnnotations object so that the user can select which CWPlots they wish to display.
>> Visual Basic will not allow me to create any New objects as type CWxxx of any sort. <<
My only other option I can think of is to dynamically create an array of CWGraph controls and keep them hidden, just to contain the CWPlots and CWAnnotations data! This would
probably cause some unwanted overhead and it seems like there is a better solution.
I am trying to avoid having to do this or create my own "mirror" CWPlotsX user type just to keep an instance of the data.
0 Kudos
Message 1 of 4
(6,817 Views)
Adam,

Yes, you can create CW controls dynamically. The following links illustrate how to do this and should get you started:

http://digital.ni.com/public.nsf/websearch/BFF489FE87875A3986256403006F5ECD?OpenDocument

This one may not be applicable, but it shows how to do it in .NET:

http://venus.ni.com/stage/we/niepd_web_display.DISPLAY_EPD4?p_guid=B4B175A57C2065D6E034080020E74861&p_node=174961&p_submitted=N&p_rank=&p_answer=&p_source=Internal

I hope that helps.

Matt P.
NI
0 Kudos
Message 2 of 4
(6,816 Views)
Matt,

This helps because now I know I can create new instances of controls, but I would only be doing this to hold several (usually about 100) instances of the CWPlots and CWAnnotations objects, specifically. I only need one instance of the CWGraph control for the user, I would like to be able to display one of ~100++ CWPlots objects on this one display.

One can surmise that the overhead of even 100 instances of CWGraph objects (all hidden, used only to store CWPlots and CWAnnotations) will not be a desirable amount. Especially when you consider that I will have multiple instances of these forms at one time.

I want to be able to do this:

where data() is an array containing a Type object containing (among other things): xPlots As Collection, xAnnotations As Collection
and, for the sake of example here, aPlots As CWPlots, aAnnotations As CWAnnotations

For i = 0 To UBound(data)
With data(i)
Set .xPlots = New Collection
Set .xAnnotations = New Collection
CwGraph1.Plots.RemoveAll

' attempt 1:
.xPlots.Add
.xPlots.Item(1) = New CWPlot
' New CWPlot causes error
' "Invalid use of New keyword"

' attempt 2:
.xPlots.Add CWGraph1.Plots.Add
' No error, but points to same CWPlot
.xPlots(1).Name = "blah"
CWGraph1.Plots.Remove(1)
' Now the CWPlot object is destroyed,
' the .xPlots references nothing
.xPlots(1).Name = "blah"
' this causes Run-time error 5,
' "Can't access item"

' attempt 3:
Set .aPlots = New CWPlots
' "Invalid use of New keyword"

' attempt 4:
.aPlots = CWGraph1.Plots
' I wish I coudl do this...error.

End With
Next i


I *could* do this (ugh):

for i = 0 to UBound(data) ' goes to about 100
With data(i)
Set .xPlots = New Collection
Load CWGraph1(i)
CWGraph1(i).Visible = False
.xPlots.Add CWGraph1(i).Plots.Add
' now xPlots references an instance of CWPlots,
' but I have to keep this control [CWGraph1(i)] alive
' so now I have ~100 CWGraph controls hidden...
End With
Next i

In summation:
CWPlots just holds data. I want to store a lot of different instances of this data without having to pull the individual elements (of which there are many).


I hope this clarifies my conundrum.

I probably could also do a CWGraph1.Plots.Add for each plot I need (about 2-3 for each Plots object), but I imagine that the CWGraph control wouldn't do very well with 900 Plots objects (all but 3 hidden).
Is there a correlation between overhead and the amount of CWPlot's in a CWGraph.Plots CWPlots collection?


Adam Rofer
Plantronics, Inc.
0 Kudos
Message 3 of 4
(6,816 Views)
There is not a way to do this with CWGraph. The only way to create a CWPlot, CWAnnotation, etc, is to call Add on the corresponding collection on the graph. The object that is created is owned by the graph, exists in the collection until you remove it, and cannot be moved to another graph. The closest that you could get to what you're trying to do is add several plots, annotations, etc., to the collection, set the Visible property to false, then set the Visible property to true when you want to show them.

If you migrate to .NET in the future, the Measurement Studio native .NET Windows Forms graphs do allow you to create the sub-objects outside of the graph. You can not set the collection on the graph, but you could create a collection and then add them
all at once, which would have the same effect as what you're trying to do.

- Elton
Message 4 of 4
(6,817 Views)