Topic
Aufruf einer eigenen FPScript-Funktion
Home page › Community › Automation and VBA › Calling your own FPScript function
- This topic has 5 replies and 2 voices and was last updated 13 years, 10 months ago ago by Thorsten Wolterink.
-
AuthorPosts
-
14.07.2011 at 12:59 #35097Thorsten WolterinkParticipant
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 wertVBA-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 WithAn 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
14.07.2011 at 12:59 #35102Thorsten WolterinkParticipantHallo,
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 wertVBA-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 WithAn 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
14.07.2011 at 13:37 #35098Bernhard KantzParticipantAccording 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.com14.07.2011 at 15:41 #35099Thorsten WolterinkParticipantHm,
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
14.07.2011 at 16:21 #35100Bernhard KantzParticipantStrange 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.com20.07.2011 at 09:58 #35101Bernhard KantzParticipantYou 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 -
AuthorPosts
- You must be logged in to reply to this topic.