Unicode and fractions

Ok… what am I missing here

Public Function feet_inch(dist as double) as string
  Dim feet As Integer
  Dim inch As Double
  Dim s As String
  If feet>0 Then s=Str(feet)+"'"
  If inch>0 Then
  End If
  If dist>0 Then // fraction
    If dist>0 And dist<=0.25 Then
    Elseif dist>0.25 And dist<=0.50 Then 
      s=s+&Ubd // 1/2
    Elseif dist>0.50 Then 
    End If
  End If
  If inch>0 Or dist>0 Then s=s+ChrB(34)
  Return s
End Function

am trying to convert a value in INCHES to FEET and Inches to the nearest 1/4"

but when I use Drawstring on the result and “fractions” come out as black diamonds

Change ChrB to Chr ?

Copied your function into a new project and it works flawlessly. I’m drawing the string into a canvas.

that was for the quote to indicate inches… its the &UBE etc that isn’t working

only difference is I’m drawing it to the graphics property of a picture which should be functionally identical to a canvas.

I am passing a length value to the above function, then using drawstring to put it in a picture… whatever could I be doing wrong?

I drew it into a picture, and it still works. I am using an older version, however. Maybe something broke along the way with hiDpi.

What textfont are you using in the picture’s graphics , and is the returned string still UTF8?

It’s encodings.

This solved it for me… looks like the encodings done INSIDE the function aren’t making their way out through the returned value.

[code]dim pic as new picture (300,300)
pic.Graphics.forecolor = &cffffff
pic.Graphics.fillrect 0,0,300,300
pic.Graphics.forecolor = &c000000

dim ret as string
ret = feet_inch(0.5)
ret = DefineEncoding(ret,encodings.UTF8)
pic.graphics.DrawString ret, 30,30

[quote=427055:@Dave S]@anon20074439 Change ChrB to Chr ?

that was for the quote to indicate inches… its the &UBE etc that isn’t working[/quote]

Using ChrB breaks the encoding of the string and sets it to Nil, you should be using Chr instead as I mentioned earlier.

It seems that you can’t ConvertEncoding from a Nil encoding to something else which is where the problem lies and makes sense, not that encoding done inside the function isn’t returned. DefineEncoding will force the encoding, if you use DefineEncoding in your function, it will work and you wont need to define the encoding again outside the function or you could use Chr and stick with ConvertEncoding.

Thanks… this was just a quickie one-off to map the dimensions of my kitchen for an upcoming remodel, so I don’t need to worry about tight code…

No probs, you had me looking for bugs in ConvertEncoding so I wanted to make sure the explanation was out there :slight_smile: