I’m trying to translate the following piece of code (as someone suggested in this forum) to be able to dynamically use passwords via credentials assets on DSN-based ODBC connections in my application:
I almost have the proper sequence of workflows if it weren’t because when I try to translate the IntPtr unmanagedString = IntPtr.Zero;
via an Assign activity, I get the error from the title. It says it’s a “validation error”, and complains about “Cannot assign from type ‘System.Object’ to type ‘System.IntPtr’ in Assign activity ‘Assign’”, but the type of my variable unManagedString, the one I’m trying to assign the IntPtr.Zero value, is not of generic Object type but IntPtr, so I don’t see where the problem is. You can see this also in the attached picture.
“CType(IntPtr.Zero) Syntax error in cast operator; two arguments separated by comma are required”
and I think @pravallikapaluri pointed out what the issue is, as there’s one argument missing.
Still I don’t understand why UiStudio is throwing the original error, and I remember using CType function in the past but I forgot what it’s for, why should I use it and if I’m gonna encounter this situation further in the future and when to expect it to happen…
Not working because it seems I have “Option Strict On”:
Compiler error(s) encountered processing expression “GetType(IntPtr).GetField(“Zero”).GetValue(Nothing)”.
Option Strict On disallows implicit conversions from ‘Object’ to ‘System.IntPtr’.
By the way, it’s a nightmare to copy&paste these error messages from the editor. Unable to select the text and copy it. It’s displayed in plenty different places and also showed as a hint message when hovering the error or the exclamation icon, but impossible to copy, unless you explicitly run a check for errors via F7 or Shift+F7, then go over the error and, again, not possible to straight copy&paste the error text, but (at least!) this time a “copy” option in the tiny context menu when right-clicking shows up… oh well… I don’t understand why companies make these basic design flaws, overcomplicating the search for errors by explicitly disabling the ability to copy text.
The CType function is used for type conversion or casting in VB.NET and other .NET languages. It allows you to convert an expression from one data type to another, provided that the conversion is valid. You might encounter the need to use CType when you have variables or values of one data type that you want to convert to a different data type.