Hi,
I guess this question is all about encoding which I think I understand after reading the docs on it. However, I cannot solve my small issue of adding a “£” symbol to a string.
I’m using value.ToString(“£0.00”) in each case to display monetary values, and the default encoding is confirmed as UTF-8 when I add a messagbox to check the string.
As per the attached screenshot, the right hand column containing only a formatted value is fine, but the middle column containing an expression adds the extra character before the £ symbol. A $ symbol works fine and I’ve also tried CHR(163) with the same incorrect result. I also just tried ChrByte() from the docs but it appears no longer valid?
I’m not saying this is the solution to your problem (looks more like a Report issue but we need a sample project that you can Zip and upload here), but Currency.ToString adds the corresponding symbol if you provide a locale:
Var c As Currency = 123.45
Var s As String = c.ToString(New locale("en-UK")) // s = £123.45
Edit: for example using locale “fr-FR” we get 123,45 €
So I have Xojo 2025v1.1, with a Windows desktop project on Windows 11 Pro.
I’m using a ListBox control, adding a new row for a sale containing various fields including productID, quantity etc.
Item.PriceRRP and Item.SubTotal are not Currency, right?
What happens when you use only Item.PriceRRP.ToString without the format?
Edit:
I copy/paste the code but didn’t find an invisible character. I had found invisible characters on users code before. I’m not saying that there are not on OPs code but at least the code here shows none.
I’ve just added a Method to the Item Class called DescriptionPrice as follows
Return me.LabelProduct + "£"
..which still gives the same erroneous character.
However, changing it to the following:
Return "£"
..correctly displays just a pound sign.
There are no invisible characters on Item.LabelProduct as they are database fields and I’ve checked the source and also tried multiple ‘products’ so it’s not jsut one corrupt text field.
Very strange.
I’ve also just realised that I use a derived string containing a formatted price in another ‘Discount’ row which works perfectly so even more confused..
I would recommend creating a copy of the project, deleting everything that isn’t allowed to leave the house, and (assuming the bug is still visible in the copy of the project) opening an issue.
It might be a Xojo bug or something Xojo could do differently/better.
What type of variable or property is me.LabelProduct? String, Text, Variant?
Can you check the encoding of that variable or property before adding in the pound sign?
I wonder if that string building is changing the encoding. I tried to reproduce your issue in a simple project, but because I’m using literals everything is UTF8 and working correctly.
Here’s what I’ve been playing with:
var PriceRRP as Double = 1.234
var s as String = " (" + PriceRRP.ToString("£0.00") + " each)"
if s.Encoding = nil then break
if s.Encoding = Encodings.UTF8 then break
OP mentions currency but the Currency type is not used. Pulling from a database and using Doubles instead that’s why the format with the sign is needed.
In one of my Projects i have to pull Doubles as a Currency Value from a mySQL Database and run into (expected) rounding issues. (Please don’t ask why i have to do this).
So i made my own Truncate Method for Currency Values, to work around those rounding issues.
Public Sub Truncate(Extends ByRef Value As Currency, DecimalPlaces As Integer)
Var Multiplier As Integer = Pow(10, DecimalPlaces)
If Value < 0 Then
Value = Ceil(Value * Multiplier) / Multiplier
Else
Value = Floor(Value * Multiplier) / Multiplier
End
End Sub
So are we saying, the database field in the string expression is setting the encoding; as opposed to UTF8 which is the Xojo default? That would make sense.
Is there best-practice around this at all? The data is actually read into an array when the app opens so should I be setting the encoding at that point?
db3.ExecuteSQL("UPDATE current_cards SET password=? WHERE ccard_id=?", _
Password.ConvertEncoding(Encodings.ISOLatin1), _
Ticketnummer.ConvertEncoding(Encodings.ISOLatin1))
(Yes, in my example it’s allowed to save a Password in Plain Text)
So just to be clear when reading data..we need to specify the field in the database is encoded to ISOLatin1 and then XOJO stores with the default (UTF8).
Then when writing, we need to convert back to the database encoding.
Lastly, does this apply to all fields or just text as your example implies Ticketnummer may be an ID/value?