Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to place multiple Annotations on the same cwgraph?

Hi,
 
I'm trying to add multiple vertical bars (annotations) on a cwgraph.
Here is the code that I have for a command button:
 
Private Sub Annotation_Click()
    S = S + 2
    CWGraph1.Annotations.Add
    CWGraph1.Annotations.Item(1).Shape.XCoordinates = Array(S, S)
    CWGraph1.Annotations.Item(1).Shape.YCoordinates = Array(-10, 10)
End Sub
What happens when I click the button, is a new annotation is added with respect to S, but the last annotation is removed.  Can someone point out the error of my ways?
 
Thanks,
 
Max
0 Kudos
Message 1 of 5
(6,637 Views)

That shouldn't be happening. Could you please post a small test project that demonstrates the problem that you're seeing? Thanks.

- Elton

0 Kudos
Message 2 of 5
(6,627 Views)

Hi Elton,

Attached is the sample project.

Max

0 Kudos
Message 3 of 5
(6,629 Views)

The annotation isn't removed. What's happening is that you're always updating the properties for the first annotation that you added, and the same annotation is updated with the new coordinates each time that you click the button. If you change your code to always use the last index into the Item property, you will see the expected results. For example:

Private Sub Annotation_Click()
    S = S + 2
    CWGraph1.Annotations.Add
    Dim index as Integer
    index = CWGraph1.Annotations.Count
    CWGraph1.Annotations.Item(index).Shape.XCoordinates = Array(S, S)
    CWGraph1.Annotations.Item(index).Shape.YCoordinates = Array(-10, 10)
End Sub

Alternatively, you can use the return value of Add to update the most recently added annotation. For example:

Private Sub Annotation_Click()
    S = S + 2
    Dim annotation As CWAnnotation
    Set annotation = CWGraph1.Annotations.Add
    annotation.Shape.XCoordinates = Array(S, S)
    annotation.Shape.YCoordinates = Array(-10, 10)
End Sub

- Elton

0 Kudos
Message 4 of 5
(6,619 Views)
Elton,
 
Works great!  Thank you very much for the explanation!
 
Regards,
 
Max
0 Kudos
Message 5 of 5
(6,614 Views)