FlexPro
HistoryBase
Ingénierie
Formation
Téléchargements
Support FlexPro
Connaissance
Communauté
À propos de nous
Références
Emplois
Contact général
Liste des revendeurs
Support FlexPro
FR
DE
EN
Porte-plaquette
Produits et solutions
Support et téléchargements
Entreprise
Magazine
Contact
Langue
MyWeisang

Paramètres du compte.

Topic

Aufruf einer eigenen FPScript-Funktion

Page d'accueil ' Communauté ' Automation et VBA ' Appel d'une fonction FPScript propre

Voir les messages de 6 - 1 à 6 (sur un total de 6)
  • Auteur
    Messages
  • #35097
    Thorsten Wolterink
    Participant

    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
    [b]Set myVariant = myFormel.Call(testWert)[/b]
    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

    #35102
    Thorsten Wolterink
    Participant

    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
    [b]Set myVariant = myFormel.Call(testWert)[/b]
    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

    #35098
    Bernhard Kantz
    Participant

    According to our test the [b]Type mismatch[/b] 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

    #35099
    Thorsten Wolterink
    Participant

    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

    #35100
    Bernhard Kantz
    Participant

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

    Support
    support@weisang.com

    #35101
    Bernhard 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

Voir les messages de 6 - 1 à 6 (sur un total de 6)
  • Vous devez être connecté pour répondre à ce sujet.