Forum FlexPro – Discuss your topic!

Aufruf einer eigenen FPScript-Funktion

Accueil > Community > Automation and VBA > Aufruf einer eigenen FPScript-Funktion

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12730

    Hallo,

    ich versuche von VBA aus eine eigene FPScript-Funktion aufzurufen. Da ich es nicht hinbekommen habe, habe ich mal ein kurzes Beispiel erstellt, dass denselben Fehler erzeugt (Fett markiert).

    FPScript-Funktion ‘FktTest’:
    Arguments wert
    Return wert

    VBA-Code:

    Dim myFormel As Formula
    Dim mySignal As Signal
    Dim myVariant As Variant
    Dim testWert As Variant
    testWert = Array(“100”)

    With ActiveDatabase.RootFolder
    ‘ Funktion zum Testen bekannt machen
    Set myFormel = .Object(“FktTest”, fpObjectTypeFormula)
    ‘ Prüfen, ob es eine Formel ist
    If TypeOf myFormel Is Formula Then Debug.Print “myFormel ist Formel”
    ‘ Ausgabe der Formel
    Debug.Print myFormel.Formula
    Set myVariant = myFormel.Call(testWert)
    Debug.Print myVariant
    End With

    An der hervorgehobenen Stelle bekomme ich immer die Fehlermeldung “Typen unverträglich”. Soweit ich die Hilfe der CALL-Methode verstehe, gibt sie doch ein Variant zurück, sodass ich die ‘Uverträglichkeit’ nicht nachvollziehen kann.

    Mit der Bitte um Unterstützung,

    Thorsten Wolterink

    #8394

    Hallo,

    ich versuche von VBA aus eine eigene FPScript-Funktion aufzurufen. Da ich es nicht hinbekommen habe, habe ich mal ein kurzes Beispiel erstellt, dass denselben Fehler erzeugt (Fett markiert).

    FPScript-Funktion ‘FktTest’:
    Arguments wert
    Return wert

    VBA-Code:

    Dim myFormel As Formula
    Dim mySignal As Signal
    Dim myVariant As Variant
    Dim testWert As Variant
    testWert = Array(“100”)

    With ActiveDatabase.RootFolder
    ‘ Funktion zum Testen bekannt machen
    Set myFormel = .Object(“FktTest”, fpObjectTypeFormula)
    ‘ Prüfen, ob es eine Formel ist
    If TypeOf myFormel Is Formula Then Debug.Print “myFormel ist Formel”
    ‘ Ausgabe der Formel
    Debug.Print myFormel.Formula
    Set myVariant = myFormel.Call(testWert)
    Debug.Print myVariant
    End With

    An der hervorgehobenen Stelle bekomme ich immer die Fehlermeldung “Typen unverträglich”. Soweit ich die Hilfe der CALL-Methode verstehe, gibt sie doch ein Variant zurück, sodass ich die ‘Uverträglichkeit’ nicht nachvollziehen kann.

    Mit der Bitte um Unterstützung,

    Thorsten Wolterink

    #9190
    Bernhard KantzBernhard Kantz
    Participant

    According to our test the Type mismatch occurs in the following line:

    Debug.Print myVariant

    This is because to try to print an array which usually requires a loop in VBA. Replacing the line by:

    Debug.Print myVariant(0)

    solved the problem.

    Support
    support@weisang.com

    #9191

    Hm,

    bei mir tritt der Fehler eine Zeile höher auf.
    Ich habe Ihre Lösung ausprobiert und auch die Zeile mit dem Print-Befehl auskommentiert.

    Der Fehler tritt weiterhin auf. Kurios.

    Thorsten Wolterink

    #9192
    Bernhard KantzBernhard Kantz
    Participant

    Strange enough we expected the error also in the line indicated by you. Please try to omit the set keyword. set should be used only if you assign an object (Signal, List or Complex in this case), otherwise an error should occur. For some reasons it did not happen in our tests.

    Support
    support@weisang.com

    #9193
    Bernhard KantzBernhard Kantz
    Participant

    You have to distinguish if you want to call a FPScript function with one argument for different values or if you want to call a FPScript function with more than one argument. The following example shows how it works:

    Sub test()

    Dim myFormel As Formula
    Dim mySignal As Signal
    Dim myVariant As Variant
    Dim testWert1 As Variant
    Dim testWert2 As Variant
    testWert1 = Array(“100”, “1”)
    testWert2 = Array(“200”, “2”)

    With ActiveDatabase.RootFolder
    ‘ Funktion zum Testen bekannt machen
    Set myFormel = .Object(“FktTest”, fpObjectTypeFormula)
    ‘ Prüfen, ob es eine Formel ist
    If TypeOf myFormel Is Formula Then Debug.Print “myFormel ist Formel”
    ‘ Ausgabe der Formel
    Debug.Print myFormel.Formula
    myVariant = myFormel.Call(testWert1, testWert2)
    Debug.Print myVariant(0, 0)
    Debug.Print myVariant(0, 1)
    Debug.Print myVariant(1, 0)
    Debug.Print myVariant(1, 1)
    End With
    End Sub

    support@weisang.com

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