You are on page 1of 11

C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.

Option Explicit
'form for changing multiple properties.
Dim FirstSelect As Long
Dim isFirstSelect As Boolean
Dim blnToColor As Boolean
Dim blnFromColor As Boolean

Private Function PopulateList(objMain As Object) As Boolean


'populate the main list
On Error GoTo ErrorHandler
Dim i As Long
Dim temp As Boolean
PopulateList = False
i = 0
Dim objObject As Object
For Each objObject In objMain
'look at each object in the picture

'if the object is a datalink and the datalink option is selected , add it to list
If objObject.ClassName = "DataLink" Then
If chkDatalink.Value Then

-1-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
lstObjects.AddItem objObject.Name

'if the object is selected, make it selected in list


If objObject.IsSelected Then
lstObjects.Selected(lstObjects.ListCount - 1) = True
PopulateList = True
If isFirstSelect Then
FirstSelect = lstObjects.ListCount - 1
isFirstSelect = False
End If
End If
End If
Else

'if the object is a datalink and the datalink option is selected , add it to list
If objObject.ClassName = "Group" Then
temp = PopulateList(objObject.ContainedObjects)
PopulateList = temp
If chkGroup.Value Then
lstObjects.AddItem objObject.Name
'if the object is selected, make it selected in list
If objObject.IsSelected And Not temp Then
lstObjects.Selected(lstObjects.ListCount - 1) = True
PopulateList = True
If isFirstSelect Then
FirstSelect = lstObjects.ListCount - 1
isFirstSelect = False
End If
End If
End If
Else

'if the object is a datalink and the datalink option is selected , add it to list
If objObject.ClassName = "OleObject" Then
temp = PopulateList(objObject.ContainedObjects)
PopulateList = temp
If chkOLE.Value Then
lstObjects.AddItem objObject.Name

'if the object is selected, make it selected in list


If objObject.IsSelected And Not temp Then
lstObjects.Selected(lstObjects.ListCount - 1) = True
PopulateList = True
If isFirstSelect Then
FirstSelect = lstObjects.ListCount - 1
isFirstSelect = False
End If
End If
End If
Else
'if the object is a datalink and the datalink option is selected , add it to list
If objObject.ClassName <> "Lookup" And chkShape Then
lstObjects.AddItem objObject.Name

'if the object is selected, make it selected in list


If objObject.IsSelected Then
lstObjects.Selected(lstObjects.ListCount - 1) = True
PopulateList = True
If isFirstSelect Then
FirstSelect = lstObjects.ListCount - 1
isFirstSelect = False
End If
End If
Else
' if object is bitmap and bitmap option selected, add to list
If objObject.ClassName = "Bitmap" Then
temp = PopulateList(objObject.ContainedObjects)
PopulateList = temp

-2-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
If chkBitmaps.Value Then
lstObjects.AddItem objObject.Name
'if the object is selected, make it selected in list
If objObject.IsSelected And Not temp Then
lstObjects.Selected(lstObjects.ListCount - 1) = True
PopulateList = True
If isFirstSelect Then
FirstSelect = lstObjects.ListCount - 1
isFirstSelect = False
End If
End If
End If
End If
End If
End If
End If
End If
Set objObject = Nothing
Next objObject
If FirstSelect > 18 Then
lstObjects.TopIndex = FirstSelect
End If
setBtnStyleState

Exit Function
ErrorHandler:
frsHandleError
End Function

Private Sub btnChange_Click()


On Error GoTo ErrorHandler
Dim objObject As Object
Dim nameNumber As Long
Dim strTemp As String
Dim strName As String
Dim test As String
Dim i As Long
Dim NameTest As Boolean
Dim blnBadName As Boolean
Dim varProperty As Variant
Dim vValue As Variant
Select Case MultiPage.Value
Case 0
'first tab selected,
strName = txtName.text
strName = LTrim(strName)
strName = RTrim(strName)
NameTest = False

'for each object that is selected, set property if desired.


For i = 0 To lstObjects.ListCount - 1
If lstObjects.Selected(i) Then
Set objObject = Application.ActiveDocument.Page.FindObject(lstObjects.List(i))
If chkSelectable.Value Then
objObject.IsSelectable = chkSelectableValue.Value
End If
If chkHighlight.Value Then
objObject.HighlightEnabled = chkHighlightValue.Value
End If
If chkVisible.Value Then
objObject.Visible = chkVisibleValue.Value
End If
If chkLayer.Value Then
objObject.Layer = txtLayer.text
'change ALL objects
frszSetDspLayers objObject.ContainedObjects, CLng(txtLayer.text)
End If
If chkToolTips.Value Then

-3-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
objObject.EnableTooltips = chkToolTipValue.Value
End If
If chkDescription.Value Then
objObject.Description = txtDescr.text
End If
If chkBtnStyle.Value Then
If chkBtnStyleValue.Value Then
objObject.ButtonStyle = lngBITMAPBUTTONPUSH
Else
objObject.ButtonStyle = lngBITMAPBUTTONNONE
End If
End If
End If
Set objObject = Nothing
Next i

'if the name is to be changed


If chkName.Value Then
Application.ActiveDocument.Page.FindObject (txtName.text)
Dim nameCont As Long
nameCont = MsgBox(txtName.text & strPostAlreadyExists & vbNewLine &
strDoYouWantToContinue, vbYesNo, "Name property")
If nameCont <> vbYes Then
Exit Sub
End If
Names:
For i = 0 To lstObjects.ListCount - 1
If lstObjects.Selected(i) Then
'object selected in list, get object in picture
Set objObject = Application.ActiveDocument.Page.FindObject(lstObjects.List(i))

'can not change OleObject name


If objObject.ClassName = "OleObject" Then
MsgBox strOleNameError
Exit Sub
End If
'test to see if the name given is valid
If Not NameTest Then
strTemp = objObject.Name
objObject.Name = txtName.text
objObject.Name = strTemp
NameTest = True
End If
Set objObject = Nothing
End If
Next i
'if the name test failed, post message and leave function
If blnBadName Then
MsgBox strInvalidName
Exit Sub
End If
'set all names to be changed to a temp name
nameNumber = 0
For i = 0 To lstObjects.ListCount - 1
If lstObjects.Selected(i) Then
Set objObject = Application.ActiveDocument.Page.FindObject(lstObjects.List(i))
objObject.Name = "FRSINVALIDTEMPNAME" + LTrim(RTrim(str(nameNumber)))
nameNumber = nameNumber + 1
Set objObject = Nothing
End If
Next i

nameNumber = 0
For i = 0 To lstObjects.ListCount - 1
'set all names to be changed to the valid name to be changed to
If lstObjects.Selected(i) Then
Set objObject = Application.ActiveDocument.Page.FindObject("FRSINVALIDTEMPNAME" +
LTrim(RTrim(str(nameNumber))))

-4-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
nameNumber = nameNumber + 1
If chkName.Value Then
If lstObjects.ListCount > 1 Then
objObject.Name = txtName.text
Else
objObject.Name = txtName.text
End If
End If
Set objObject = Nothing
End If
Next i
End If

lstObjects.Clear
FirstSelect = 0
isFirstSelect = True
PopulateList Application.ActiveDocument.Page.ContainedObjects
Case 1
'second page is selected
Dim objTemp As Object
For i = 0 To lstObjects.ListCount - 1
If lstObjects.Selected(i) Then
Set objObject = Application.ActiveDocument.Page.FindObject(lstObjects.List(i))
'if the object is selected, change the color
changeColor objObject
Set objObject = Nothing
End If
Next i
End Select
Exit Sub
ErrorHandler:
If err.Number = -2147200630 Then
Resume Names
End If
blnBadName = True
Resume Next
End Sub

Private Sub changeColor(objObject As Object)


'this function is used to do a search and replace on all colors in an object
On Error GoTo ErrorHandler
Dim objContained As Object
'if the object is a group, we will look at the objects in the group
If objObject.ClassName = "Group" Then
For Each objContained In objObject.ContainedObjects
changeColor objContained
Set objContained = Nothing
Next
Else
'change the colors that are selected to be changed
If chkForeColor Then
If frsHasProperty(objObject, "ForegroundColor") Then
'compare base color and then change if the same
If objObject.ForegroundColor = clrFromColor.Color Then
objObject.ForegroundColor = clrToColor.Color
End If
End If
End If
If chkBackColor Then
If frsHasProperty(objObject, "BackgroundColor") Then
'compare base color and then change if the same
If objObject.BackgroundColor = clrFromColor.Color Then
objObject.BackgroundColor = clrToColor.Color
End If
End If
End If
If chkEdgeColor Then
If frsHasProperty(objObject, "EdgeColor") Then

-5-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
'compare base color and then change if the same
If objObject.EdgeColor = clrFromColor.Color Then
objObject.EdgeColor = clrToColor.Color
End If
End If
End If
End If
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub btnDesel_Click()


'deselect all
On Error GoTo ErrorHandler
Dim objObject As Object
Dim i As Long
If chkSelPicture.Value Then
Application.ActiveDocument.Page.Select
End If
For i = 0 To lstObjects.ListCount - 1
lstObjects.Selected(i) = False
Next i
setBtnStyleState
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub btnExit_Click()


'exit form
On Error GoTo ErrorHandler
Unload MyLayers
Me.Hide
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub btnLayer_Click()


'get the desired layer from our layer form
On Error GoTo ErrorHandler
MyLayers.Show
txtLayer.text = str(MyLayers.rtnNumber)
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub btnSelAll_Click()


'select all items in the list box
On Error GoTo ErrorHandler
Dim objObject As Object
Dim i As Long
If chkSelPicture.Value Then
Application.ActiveDocument.Page.Select
End If

'cycle all items in the listbox setting the correct property


For i = 0 To lstObjects.ListCount - 1
lstObjects.Selected(i) = True
If chkSelPicture.Value Then
Set objObject = Application.ActiveDocument.Page.FindObject(lstObjects.List(i))
objObject.SelectObject False
Set objObject = Nothing
End If
Next i
setBtnStyleState

-6-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkBackColor_Click()


'set the enabling of the back color value = to the back color check box (enabled if true,
disabled if false)
On Error GoTo ErrorHandler
If Not chkForeColor.Value Then
chkColors.Value = False
End If
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkBitmaps_Click()


'clear and then repopulate the list box. We do this since the check box of what is
visible has changed
On Error GoTo ErrorHandler
lstObjects.Clear
FirstSelect = 0
isFirstSelect = True
PopulateList Application.ActiveDocument.Page.ContainedObjects
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkBtnStyle_Click()


'set the enabling of the button style value = to the button style check box (enabled if
true, disabled if false)
On Error GoTo ErrorHandler
chkBtnStyleValue.Enabled = chkBtnStyle.Value
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub setBtnStyleState()


Dim bFound As Boolean
Dim i As Long
Dim objObject As Object
bFound = False
For i = 0 To lstObjects.ListCount - 1
If lstObjects.Selected(i) Then
Set objObject = Application.ActiveDocument.Page.FindObject(lstObjects.List(i))
If objObject.ClassName = "Bitmap" Then
bFound = True
Set objObject = Nothing
Exit For
End If
Set objObject = Nothing
End If
Next i
chkBtnStyle.Enabled = bFound
End Sub

Private Sub chkColors_Click()


'set all values
On Error GoTo ErrorHandler
chkForeColor.Value = chkColors.Value
chkBackColor.Value = chkColors.Value
chkEdgeColor.Value = chkColors.Value
Exit Sub
ErrorHandler:
frsHandleError

-7-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
End Sub

Private Sub chkDatalink_Click()


'clear and then repopulate the list box. We do this since the check box of what is
visible has changed
On Error GoTo ErrorHandler
lstObjects.Clear
FirstSelect = 0
isFirstSelect = True
PopulateList Application.ActiveDocument.Page.ContainedObjects
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkDescription_Click()


'set the enabling of the description text value = to the description check box (enabled if
true, disabled if false)
On Error GoTo ErrorHandler
txtDescr.Enabled = chkDescription.Value
If txtDescr.Enabled Then
txtDescr.SetFocus
End If
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkEdgeColor_Click()


'set the enabling of the edge color value = to the edge color check box (enabled if true,
disabled if false)
On Error GoTo ErrorHandler
If Not chkForeColor.Value Then
chkColors.Value = False
End If
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkForeColor_Click()


'set the enabling of the forecolor value = to the forecolor check box (enabled if true,
disabled if false)
On Error GoTo ErrorHandler
If Not chkForeColor.Value Then
chkColors.Value = False
End If
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkOLe_Click()


'clear and then repopulate the list box. We do this since the check box of what is
visible has changed
On Error GoTo ErrorHandler
lstObjects.Clear
FirstSelect = 0
isFirstSelect = True
PopulateList Application.ActiveDocument.Page.ContainedObjects
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkGroup_Click()


'clear and then repopulate the list box. We do this since the check box of what is
visible has changed

-8-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
On Error GoTo ErrorHandler
lstObjects.Clear
FirstSelect = 0
isFirstSelect = True
PopulateList Application.ActiveDocument.Page.ContainedObjects
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkHighlight_Click()


'set the enabling of the highlight value = to the highlight check box (enabled if true,
disabled if false)
On Error GoTo ErrorHandler
chkHighlightValue.Enabled = chkHighlight.Value
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkLayer_Click()


'set the enabling of the layer value = to the layer check box (enabled if true, disabled
if false)
On Error GoTo ErrorHandler
btnLayer.Enabled = chkLayer.Value
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkName_Click()


'set the enabling of the name value = to the name check box (enabled if true, disabled if
false)
On Error GoTo ErrorHandler
txtName.Enabled = chkName.Value
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkSelectable_Click()


'set the enabling of the selectable value = to the selectable check box (enabled if true,
disabled if false)
On Error GoTo ErrorHandler
chkSelectableValue.Enabled = chkSelectable.Value
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkSelPicture_Click()


'look at what is selected in the list box and select it in the picture
On Error GoTo ErrorHandler
Dim objObject As Object
Dim i As Long
Application.ActiveDocument.Page.Select
For i = 0 To lstObjects.ListCount - 1
If lstObjects.Selected(i) Then
Set objObject = Application.ActiveDocument.Page.FindObject(lstObjects.List(i))
objObject.SelectObject False
Set objObject = Nothing
End If
Next i
Exit Sub
ErrorHandler:
frsHandleError
End Sub

-9-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
Private Sub chkShape_Click()
'clear and then repopulate the list box. We do this since the check box of what is
visible has changed
On Error GoTo ErrorHandler
lstObjects.Clear
FirstSelect = 0
isFirstSelect = True
PopulateList Application.ActiveDocument.Page.ContainedObjects
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkToolTips_Click()


'set the enabling of the tooltip value = to the tooltip check box (enabled if true,
disabled if false)
On Error GoTo ErrorHandler
chkToolTipValue.Enabled = chkToolTips.Value
chkHighlight.Value = chkToolTips.Value
chkDescription.Value = chkToolTips.Value
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub chkVisible_Click()


'set the enabling of the vis value = to the vis check box (enabled if true, disabled if
false)
On Error GoTo ErrorHandler
chkVisibleValue.Enabled = chkVisible.Value
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub clrFromColor_ColorChanged(ByVal Color As Long)


'set flag that the from color has been selected
On Error GoTo ErrorHandler
blnFromColor = True
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub clrToColor_ColorChanged(ByVal Color As Long)


'set flag that the to color has been selected
On Error GoTo ErrorHandler
blnToColor = True
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub lstObjects_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As


Single, ByVal Y As Single)
'this event will select objects on the picture if the flag is set
On Error GoTo ErrorHandler
Dim objObject As Object
Dim i As Long
If chkSelPicture.Value Then
'the flag is set
Application.ActiveDocument.Page.Select
For i = 0 To lstObjects.ListCount - 1
If lstObjects.Selected(i) Then
'for all that are selected in the list, select them in the picture
Set objObject = Application.ActiveDocument.Page.FindObject(lstObjects.List(i))
objObject.SelectObject False
Set objObject = Nothing

-10-
C:\1. Jonathan\22. Programming_DeltaV\forPropCustomization\formProperties2.txt lunes, 02 de enero de 2017 10:46 a.m.
End If
Next i
End If
setBtnStyleState
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub UserForm_Initialize()


'Initialization for this form. Most of the work is done in populatelist
On Error GoTo ErrorHandler
FirstSelect = 0
MultiPage.Value = 0
isFirstSelect = True
PopulateList Application.ActiveDocument.Page.ContainedObjects

'TFS159853
Me.Caption = strPropertyFrmCap
Label1.Caption = strPicureObjectsCap
chkSelPicture.Caption = strSelectionOnPicCap
frmObjects.Caption = strListFilterCap
chkDatalink.Caption = strDatalinksLabelCap
chkShape.Caption = strShapesLabelCap
chkGroup.Caption = strGroupsLabelCap
chkBitmaps.Caption = strBitmapsLabelCap
MultiPage.Pages.Item("pgeProperty").Caption = strPropertyTabCap
MultiPage.Pages.Item("pgeSearchReplace").Caption = strSearchAndReplaceTabCap
Label2.Caption = strEnableChangeCap
Label3.Caption = strChangeValueCap
btnChange.Caption = strChangeBtnCap
btnExit.Caption = strExitBtnCap
btnSelAll.Caption = strSelectAllBtnCap
btnDesel.Caption = strDeselectAllBtnCap
Exit Sub
ErrorHandler:
frsHandleError
End Sub

Private Sub frszSetDspLayers(objObject As Object, DspLayer As Long)


On Error GoTo ErrorHandler
Dim objLocalObject As Object
For Each objLocalObject In objObject
If objLocalObject.ClassName = "Group" Then
'call recrusively to walk down the list
frszSetDspLayers objLocalObject.ContainedObjects, DspLayer
Else
If frsHasProperty(objLocalObject, "Layer") Then
objLocalObject.Layer = DspLayer
End If
End If
Set objLocalObject = Nothing
Next
Exit Sub
ErrorHandler:
frsHandleError
End Sub

-11-