In my thread class, where I have to update the UI I pass messages through to a timer event handler which modifies the UI. For flexibility, the messages passed contain variants. This gives a problem when I pass a fixed string through the variant, thus:
t.UIwriter ("Some stringy data")
where UIwriter is defined as:
[quote]UIwriter (arg1 as variant)
[/quote]
The problem is that this fixed data enters the variant as a String rather than as a Text type, which gives a problem at the receiving end which assumes it is being given a Text item. So I have to do:
dim msg as text
msg = "Some stringy data"
t.UIwriter (msg)
and all is OK. But this is clumsy. If I happen to do as follows:
Sure, you could do that, but be careful. If the String’s encoding is nil, that will generate an exception. If you’re sure your Strings will always be encoded, it’s no problem. Text -> String always works.
Not that, no. But it would be an odd construct anyway. If you want to force a string literal to Text, use CType, as in v = CType( "some string", Text ) or assign it to a Text constant like const kMyText as Text = "some string". This is generally not needed as encoded Strings can always be converted to Text, and Text will convert to UTF8-encoded Strings.
However, if you write the method as discussed, it won’t be necessary either way. The method will handle the conversion for you so it won’t matter if you pass in a String or Text.