Forum FlexPro – Discuss your topic!

Find & Replace

Accueil > Community > General > Find & Replace

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #12900
    HerveM1234HerveM1234
    Participant

    Hi,

    Is there a way to perform a string replacement in a complete database?
    i.e. : I would like to replace the string “aaa” by “bbb” in every formulas, (formulas name & content) diagrams, tables,… of the database.

    Thanks for help

    #8560
    HerveM1234HerveM1234
    Participant

    Hi,

    Is there a way to perform a string replacement in a complete database?
    i.e. : I would like to replace the string “aaa” by “bbb” in every formulas, (formulas name & content) diagrams, tables,… of the database.

    Thanks for help

    #9423
    Bernhard KantzBernhard Kantz
    Participant

    There is no simple way of replacing strings in object names and (embedded) formulas. Of course one can program a small VBA script that crawls through the whole database and changes the desired entities (names, contents).

    #9425
    HerveM1234HerveM1234
    Participant

    OK for that.

    Would it be possible to get an example of this kind of VBA script?

    Thanks in advance.

    #9426
    Bernhard KantzBernhard Kantz
    Participant

    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
    
    #9427
    HerveM1234HerveM1234
    Participant

    Great, thanks a lot !

    maybe yo should had this feature to the next release !

    #9428
    HerveM1234HerveM1234
    Participant

    I’ve tested the code : perfect. excepted if there is FPScript expressions embedded in a diagram. These expressions are not modified by the macro.
    Thanks again!

    #9429
    Bernhard KantzBernhard Kantz
    Participant

    For 2d diagrams the code example just handles the datasets for the curves (there was a c&p error for the x dataset). There are of course many locations (e.g. axis scaling) where embedded FPScript code may occur. Handling all the cases would have blown up the code.
    From the overall structure one easily can add the functionality needed in ones specific case.

    #28939
    AnonymAnonym
    Participant

    Hallo,

    ich bin noch kein Profi, was VBA angeht. Ich würde gerne bitte wissen, wie der Aufruf aussieht, wenn ich VisitFormula anwenden möchte.

    Bei mir geht es auch darum, die Zeichenkette (String File) in meinen Formeln in der Objektliste durch einen anderen String zu ersetzen. Danke im Voraus.

    Was tippe ich in meinen Direktbereich? Danke

     

    #28940
    Bernhard KantzBernhard Kantz
    Participant

    Wenn Sie lediglich in allen Formeln, eine Zeichenkette durch eine andere ersetzen wollen, sollten Sie in der Select-Case-Anweisung im Sub Visit den Fall für das 2D-Diagramm entfernen.

    Ersetzen Sie dann die beiden String-Konstanten durch Ihre Zeichenketten und führen dann das Sub SearchReplace aus.

    Das Sub VisitFormula können Sie nicht dafür verwenden. Es ist Teil des Visitor-Patterns und dient zur Korrektur einer Formel.

     

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.