FlexPro
HistoryBase
Engineering
Training
Downloads
FlexPro-Support
Wissen
Community
Über Uns
Referenzen
Jobs
Allgemeiner Kontakt
Händlerverzeichnis
FlexPro-Support
DE
EN
FR
Placeholder
Produkte und Lösungen
Support und Downloads
Unternehmen
Magazin
Kontakt
Sprache
MyWeisang

Account Einstellungen

Topic

Find & Replace

Startseite ' Community ' Allgemein ' Find & Replace

Anzeigen von 10-Stellen - 1 bis 10 (von insgesamt 10)
  • Autor
    Beiträge
  • #34607
    HerveM1234
    Teilnehmer

    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

    #34614
    HerveM1234
    Teilnehmer

    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

    #34608
    Bernhard Kantz
    Teilnehmer

    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).

    #34609
    HerveM1234
    Teilnehmer

    OK for that.

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

    Thanks in advance.

    #34610
    Bernhard 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.

    [code]
    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
    [/code]

    #34611
    HerveM1234
    Teilnehmer

    Great, thanks a lot !

    maybe yo should had this feature to the next release !

    #34612
    HerveM1234
    Teilnehmer

    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!

    #34613
    Bernhard Kantz
    Teilnehmer

    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.

    #34615
    Anonym
    Teilnehmer

    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

     

    #34616
    Bernhard Kantz
    Teilnehmer

    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.

     

Anzeigen von 10-Stellen - 1 bis 10 (von insgesamt 10)
  • Du musst angemeldet sein, um auf dieses Thema antworten zu können.