Topic
Find & Replace
Startseite ' Community ' Allgemein ' Find & Replace
- Dieses Thema hat 9 Antworten sowie 3 Teilnehmer und wurde zuletzt vor vor 4 Jahren von Bernhard Kantz aktualisiert.
-
AutorBeiträge
-
04.02.2016 um 10:38 Uhr #34607HerveM1234Teilnehmer
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
04.02.2016 um 10:38 Uhr #34614HerveM1234TeilnehmerHi,
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
05.02.2016 um 08:39 Uhr #34608Bernhard KantzTeilnehmerThere 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).
05.02.2016 um 09:50 Uhr #34609HerveM1234TeilnehmerOK for that.
Would it be possible to get an example of this kind of VBA script?
Thanks in advance.
08.02.2016 um 09:20 Uhr #34610Bernhard KantzTeilnehmerSince 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 ExplicitConst csSearch As String = “Jan”
Const csReplace As String = “01”Public Sub SearchReplace()
Visit ThisDatabase.RootFolder
End SubPrivate Sub Visit(ByRef oFld As Folder)
Dim cllObs As FpObjects
Set cllObs = oFld.ObjectsDim 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 SubPrivate Sub VisitFormula(ByRef oFml As Formula)
oFml.Formula = Replace(oFml.Formula, csSearch, csReplace)
End SubPrivate 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]08.02.2016 um 14:31 Uhr #34611HerveM1234TeilnehmerGreat, thanks a lot !
maybe yo should had this feature to the next release !
10.02.2016 um 18:08 Uhr #34612HerveM1234TeilnehmerI’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!11.02.2016 um 08:22 Uhr #34613Bernhard KantzTeilnehmerFor 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.11.05.2021 um 14:28 Uhr #34615AnonymTeilnehmerHallo,
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
14.05.2021 um 10:17 Uhr #34616Bernhard KantzTeilnehmerWenn 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.
-
AutorBeiträge
- Du musst angemeldet sein, um auf dieses Thema antworten zu können.