Convert Variant To String Using CType

I’m updating a client’s app since they finally got off of OS X 10.6.8. It was built with 2013R3.3. Now I’m using 2015R3.1. When trying to run the app in the new Xojo version I get the following compile error:

Extension method REALbasic.DefineEncodings requires a conversion from type Variant to type String; use CType to explicity convert first. vSourceID=rs.IdxField(1).Value.DefineEncoding(Encodings.UTF8)

The local variable vSourceID is defined as a String.

So I guess I’m wondering how to rebuild the line of code to work with the new version? I did look around the forum and saw some examples but not one that would fit nicely into the existing line of code. I was thinking something like:

vSourceID=Str(rs.IdxField(1).Value).DefineEncoding(Encodings.UTF8)

That seems to work but I’m not sure it’s best.

Thanks.

it would be working if you would use local variables for intermediate results.
e.g. a string variable would cause the variant to go to string.
Or you add a .stringValue after the value to ask for string explicitly.

I’d use StringValue:

vSourceID = rs.IdxField(1).StringValue.DefineEncoding(Encodings.UTF8)