Textencoding nightmare

Hi again!

I would like to understand more about textencodings because I seem to run many problems with every project I make. And just because I can’t define those right.

I have one web project (standalone windows with mssql connection) where I read and write from isolatin9 database. I don’t know the right way to define encoding to the RecordSet I pull from database. And when to convert encoding to put to textarea or textfield. And back from textfield to recordset.

My database has isolatin9 encoding so probably i need to define recordset with that. Or do I define it when I put data from recordset to textfield? And when do I convert it to utf8 because it seems to be that on textfield anyway? I think it’s not possible to convert if it’s not defined first. I’ve noticed that my textfield have nul encoding (even if there is text from database already) until I type text there, at that moment it changes to utf8.

Is there some tutorial or sample project that explain all this because my head is spinning. And thanks for reading :slight_smile:

Jukka

http://www.xojo.com/blog/en/2013/08/why-are-there-diamonds-in-my-user-interface.php

http://www.realsoftwareblog.com/2013/01/encodings-what-are-they.html

ANY time you get data from outside your app you will need to DEFINE the encoding
So when you read from sockets, databases, files, serial ports, http - anything NOT created IN your app

When you get data from mysql into a variable do something like

dim s as string = DefineEncoding(recordset.field("name").Stringvalue, Encodings.THE RIGHT ENCODING FOR THIS DATA )

or

textfield1.text = DefineEncoding(recordset.field("name").Stringvalue, Encodings.THE RIGHT ENCODING FOR THIS DATA )

to send the data TO the db you may need to CONVERT the encoding so the DB can handle it properly

another simple rule: keep everything in UTF :slight_smile:

Thanks Norman.

One more question :slight_smile:

When I place text to textfield defining it is isolatin9, like yours second example, does this textfield convert it automatically to utf8, or does it stay as isolatin9?

Jukka

TextField converts it to UTF-8.