Conversion problem

Text entered in a text field appears garbled when I store the text in a structure and display it later on in a label.
It is text with diacritics.

I tried to convert it using:

myLabel.text = ConvertEncoding(myLabel.text, Encodings.UTF8)

but that does not solve it?

Ideas welcome…

From the docs: [quote]Unlike String variables, a string field has a fixed size and does not store text encoding information.

Just as you convert text to a specific encoding when writing it to a file or a socket, and assign the correct encoding to it when reading it back in, you must convert strings to a specific encoding when you assign them to a structure and define them to the correct encoding when reading them back out.[/quote]

OK, I understand what you are saying, but I do not understand why the string becomes garbled. It only lives in memory, when I assign them to a global var it remains intact? How come?

A Structure is a MemoryBlock with predefined “fields.” Storing a string in a MemoryBlock will retain the bytes without the encoding so retrieving it later into a string variable will leave you with TextEncoding of nil. ConvertEncoding will not work on that, nor do you really need to convert anything. Use DefineEncoding instead.

I’m curious why you’re using a Structure at all. Couldn’t you define a class with the fields you need as properties instead?

A structure stores strings differently than a variable created with the Dim command. The Dim variables store all information about a string, including its encoding; a structure only stores the data bytes of the string. You’ll need to use DefineEncoding on the data when you pull it back out of the structure.

[quote=45737:@Kem Tekinay]A Structure is a MemoryBlock with predefined “fields.” Storing a string in a MemoryBlock will retain the bytes without the encoding so retrieving it later into a string variable will leave you with TextEncoding of nil. ConvertEncoding will not work on that, nor do you really need to convert anything. Use DefineEncoding instead.

I’m curious why you’re using a Structure at all. Couldn’t you define a class with the fields you need as properties instead?[/quote]

Ehm… I looked for something like an array but with the possibility to define certain datatypes and I came across this structure thing (I come from Delphi) and I was curious about it. So I started using it in a project. No problems whatsoever until I noticed this.

Could you give an example of the DefineEncoding solution? Thanks.

dim s as string = myStruct.StringField
s = s.DefineEncoding( Encodings.UTF8 )

Is there a reason you can’t use a custom CLASS instead of a structure?
Structure cannot contain a “normal” string for reasons stated above…
and are normally (but not exclusively) used for communicating with DECLARES and external API’s

Well, I ‘discovered’ these structures in the manual and thought ‘let’s give it a try’…

Avoid structures for 99.9% of things
They are great for reading & writing fixed format files, reading & writing data to a serial or network port or for making calls to declares that require structures

But for MOST day to day uses you don’t want them as they are not nearly as flexible as a Class

Ok guys, I’m convinced. Now I have to see if I get this fixed with a class and the find/replace routines in the IDE…

Thanks :S