DeletePen Method Example
The following example uses the Count property of the Pens Collection for the Chart, Chart1, as an index to delete the last pen added to the Chart.
Dim x As Integer
x = Chart1.Pens.Count
Chart1.DeletePen x
The following example deletes a pen in a ChartnamedChart1,and then replaces it with another one using the AddPen method, if it does not already exist.
Private Sub Chart1_Click()
'Select a pen on user Click
'Check if user wants to delete it
Dim Strtn as string
Dim Inti as integer
Strtn = Chart1.CurrentPen
Msgprompt = "You have selected Pen : " & Chart1.Pens.Item(Strtn).Source & vbCrLf & "Do you want to remove it ?"
user_reponse = MsgBox(Msgprompt, vbYesNo, "Removing Pen")
If user_reponse = 6 Then
Chart1.DeletePen (Strtn)
End If
End Sub
Private Sub DELPEN_Click()
'delete all pen from the pen collection under a specific chart
Dim Inti as integer
If Chart1.Pens.Count <> 0 Then
For Inti = Chart1.Pens.Count To 1 Step -1
Chart1.DeletePen (Inti)
Next Inti
End If
End Sub
Private Sub PBADDREALPEN_Click()
'Add pen to the pen collection for a given Chart
'after checking the pens are not already inside the pen collection
If Chart1.Pens.Count <> 0 Then
' first time the chart is used the collection contains a default pen
Chart1.DeletePen (1)
End If
checkifalreadyexist ("Fix32.Alice.MyTag1")
checkifalreadyexist ("Fix32.Alice.MyTag2")
checkifalreadyexist ("Fix32.Alice.MyTag3")
End Sub
Function checkifalreadyexist(Tagname As String)
'check if the pen if not already inside the collection
Dim loc_tagname As String
loc_tagname = Tagname & ".F_CV"
Egu_tagname = Tagname
If Chart1.Pens.Count = 0 Then
Chart1.AddPen (loc_tagname)
hiEGU = Readvalue(Egu_tagname & ".A_Ehi")
loEGU = Readvalue(Egu_tagname & ".A_Elo")
Else
Tag_found = False
For i = 1 To Chart1.Pens.Count
If UCase(loc_tagname) = UCase(Chart1.Pens.Item(i).Source) Then
Tag_found = True
Else
End If
Next i
If Tag_found = False Then
Chart1.AddPen (loc_tagname)
Tag_found = False
End If
End If
End Function