Why do ASCII characters differ from Excel for presentation by code in VBA?

Asked

Viewed 810 times

1

Does anyone know why this occurs?

I need to use font characters "Wingdings 3" in Labels dynamically created in a form of VBA.

If these Labels are created directly in the form the problem does not occur, for example when creating a Label and copy the desired character in your Caption and selecting the source "Wingdings 3", the Label presents the character correctly, however, when using Chr(131) in the code for another’s Caption Label, something like the character appears Chr(156) from the same source (instead of appearing a full arrow to the left, appears a small and thin arrow to the right).

The code below lists some characters from this font, and it is clear that they differ totally from the characters ASCII of Excel accessed by Menu: Insert/Symbols/Symbol.

Got a way to fix it or I’m doing something wrong?

Dim i As Integer

Dim str As String

str = ""

For i = 33 To 255

  str = str & Chr(i)

Next i

Label1.Width = 500

Label1.Height = 500

Label1.Font.Name = "Wingdings 3"

Label1.Caption = str
  • 2

    Above 127 is no longer ASCII, and now depends on knowing the encoding used by the interface you are using.

1 answer

2


The solution was thus obtained:

I did a test and put two Labels on the form and one of them changed the source to "Wigdings 3" and the other was left with "Tahoma".

By code, changed the font of the two labels for "Wingdings 3", but by sending the same Chr(i) with values of i greater than 127, only the Label with "Wingdings 3" showed the characters correctly, that is, the command I gave to change the source of the Label is not being recognised in the execution of the code by VBA.

Therefore, to use characters ASCII above 127 by code in the VBA, the same desired font must be placed on the object that will receive these characters, otherwise if they are parameterized with other sources these characters will not correspond to those presented by Excel (Insert/Symbols/Symbol), even when the source of the object is changed by the code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.