VBScriptEngine - Compare Enum (Return value) with Integer #625
Replies: 2 comments 1 reply
-
Hi @DanielGerlach2, A .NET enum is not an integer, so that kind of comparison isn't possible without explicit conversion or additional setup. The recommended approach is to expose the enum type to the script engine: ScriptEngine.AddHostType(GetType(FieldTypeEnum)) You could then perform type-safe enum comparison in script code: If App.GetFieldType(""Field1"") Is FieldTypeEnum.ftUnknown Then
...
End If
If that's your requirement, then it's probably best not to expose Good luck! |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the quick answer. The code previously worked without any problems with the MSScriptcontrol and now the Clearscript should be used. https://www.file-upload.net/download-15445694/tstClearscript_625.zip.html |
Beta Was this translation helpful? Give feedback.
-
I have code that is executed via vbscriptengine, where a function returns an enum.
Definition:
Function GetFieldType(Field as String) as FieldTypeEnum
Enum:
Public Enum FieldTypeEnum As Integer
ftUnknown = 0
ftString = 10
ftDate = 8
ftCurrency = 5
End Enum
Unfortunately, a comparison between Enum and Integer is not possible.
If App,GetFieldType("Field1") = 0 Then
...
End If
Throws the Error:
Type mismatch\Type mismatch
If I change the definition to "Function GetFieldType(Field as String) as Integer" the comparision is possible, but I don't want to change the function definition or the code to be executed.
Which settings are necessary so that the comparison of an enum with an intger is possible?
Beta Was this translation helpful? Give feedback.
All reactions