ChrB() function Issue...

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
351
Office Version
  1. 2003 or older
Platform
  1. Windows
In VBA "!" has the same ASC, ASCB, ASCW values ...
?ASC("!")
33
?ASCB("!")
33
?ASCW("!")
33
But € has different ASC, ASCB, ASCW values ...
?ASC("€")
128
?ASCB("€")
172
?ASCW("€")
8364

Which I understand... But the reverse functions Chr, ChrB, and ChrW do not exactly convert back the integer values.
?Chr(128)

?ChrW(8364)

?StrConv(ChrB(172), vbUnicode)
"¬"

How to get ChrB() to give, for example, € for integer 172? (Note: StrConv(ChrB(33), vbUnicode) gives correct output! So, the Issue seems to be around 2-byte characters.)
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How to get ChrB() to give, for example, € for integer 172? (Note: StrConv(ChrB(33), vbUnicode) gives correct output! So, the Issue seems to be around 2-byte characters.)
I don't believe you can since ChrB() is only returning the 1 byte of the 2 bytes that make up the character.

Per Microsoft: Chr function (Visual Basic for Applications)
"The ChrB function is used with byte data contained in a String. Instead of returning a character, which may be one or two bytes, ChrB always returns a single byte."
 
Upvote 0
@Alex Blakenburg; Thanks...

@Scott Huish; Yes, as an alternate ChrW works fine ... But it was to better understand why ChrB is not a True reverse version of AscB... Like Chr and Asc, and AscW and ChrW.
 
Upvote 0

Forum statistics

Threads
1,216,434
Messages
6,130,611
Members
449,584
Latest member
c_clark

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top