SupportCommunity General Find & Replace Antwort auf: Find & Replace

#9426
Bernhard KantzBernhard Kantz
Teilnehmer

Since the names to change occur in many different locations, it is no easy task. The following example just handles object names, formula contents and datasets for 2d diagrams.


Option Explicit

Const csSearch As String = "Jan"
Const csReplace As String = "01"

Public Sub SearchReplace()
    Visit ThisDatabase.RootFolder
End Sub

Private Sub Visit(ByRef oFld As Folder)
    Dim cllObs As FpObjects
    Set cllObs = oFld.Objects
    
    Dim oObj As FpObject
    For Each oObj In cllObs
        Select Case oObj.ObjectType
            Case fpObjectTypeFolder
                Visit oObj
            Case fpObjectTypeFormula
                VisitFormula oObj
            Case fpObjectType2DDiagram
                VisitDiagram2D oObj
        End Select
        ' rename object itself
        Dim sNewName As String
        sNewName = Replace(oObj.Name, csSearch, csReplace)
        If sNewName  oObj.Name Then
            oObj.Rename sNewName, fpRenamingOptionsDontCorrectReferences
        End If
    Next oObj
End Sub

Private Sub VisitFormula(ByRef oFml As Formula)
    oFml.Formula = Replace(oFml.Formula, csSearch, csReplace)
End Sub

Private Sub VisitDiagram2D(ByRef oDiag2D As Diagram2D)
    Dim oCurve As Curve2D
    For Each oCurve In oDiag2D.Curves
        With oCurve.Data
            .DataSet = Replace(.DataSet, csSearch, csReplace)
            .XDataSet = Replace(.XDataSet, csSearch, csReplace)
        End With
    Next oCurve
End Sub