MS Office Forum / Word / Programming / May 2006
Using Asc and Chr
|
|
Thread rating:  |
Greg Maxey - 22 May 2006 14:57 GMT This is an ongoing issue in the Document Management group and I wanted to bring it up here in hopes of getting the right people engaged.
If I insert any one of the ten "arrow" symbols using Insert>Symbol>Symbols>Font Symbol and run the following code with any one of theses symbols selected it returns a value of 40 and inserts a left side paren symbol:
Sub Test() Dim pAsc As Long pAsc = Asc(Selection) Selection.Range.InsertAfter Chr(pAsc) End Sub
Why does this happen?
The question in the Documanagement group is how do you get the correct ASCII code for symbols?
Thanks.
Dave Lett - 22 May 2006 15:42 GMT Hi Greg,
Have a look at the article "Finding and replacing symbols" at http://word.mvps.org/FAQs/MacrosVBA/FindReplaceSymbols.htm
Does the following help??
Dim sFont As String Dim lCharNum As Long Dim oRng As Range Set oRng = Selection.Range oRng.Collapse Direction:=wdCollapseEnd With Dialogs(wdDialogInsertSymbol) sFont = .Font lCharNum = .CharNum End With oRng.InsertSymbol CharacterNumber:=lCharNum, Font:=sFont, Unicode:=True
HTH, Dave
> This is an ongoing issue in the Document Management group and I wanted > to bring it up here in hopes of getting the right people engaged. [quoted text clipped - 16 lines] > > Thanks. Dave Lett - 22 May 2006 15:47 GMT Hi Greg,
I forgot to add probably the most important part: Why does this happen?
According to the Word VBA help topic "InsertSymbol Method":
Unicode Optional Variant. True to insert the unicode character specified by CharacterNumber; False to insert the ANSI character specified by CharacterNumber. The default value is False.
Therefore, it's happening because you're inserting the ANSI character, instead of the Unicode character, I believe.
HTH, Dave
> This is an ongoing issue in the Document Management group and I wanted > to bring it up here in hopes of getting the right people engaged. [quoted text clipped - 16 lines] > > Thanks. Greg Maxey - 22 May 2006 16:29 GMT Dave,
Thanks. The key quesition from the OP in the docmenent management is "how do you determine the ASCII code of symbol?"
Using this adaptation of the code you provided with a right arrow selected:
Sub Test1() Dim sFont As String Dim lCharNum As Long Dim oRng As Range Set oRng = Selection.Range oRng.Collapse Direction:=wdCollapseEnd With Dialogs(wdDialogInsertSymbol) sFont = .Font lCharNum = .CharNum MsgBox lCharNum End With End Sub
I get -3922. The OP thinks the correct code is 117. I am not very knowledgeable with ASCII codes so therefore I don't know if I am coming closer to answering the question or not ;-)
Helmut Weber - 22 May 2006 16:41 GMT Hi Greg,
add 4096 to the negative value, you get. I think, the OP is wrong.
It is chr(174).
If you google for 4096 and my decent, ordinary name, you'll find more information, some of which solved some problems.
 Signature Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
Greg Maxey - 22 May 2006 17:48 GMT Helmut,
I agree the OP must be mistaken, because as Dave says and I confirmed 122 produces a small case "u." I am not sure I fully understand the relationship of 4096, the unicode, and the ASCII code. Using Chr(174) I get the symbol for "registered" or a circle inscribing the letter R.
Perhaps the answer is that you can't determine the ASCII character of a symbol that is not part of the ASCII set.
Lesley Regan - 22 May 2006 18:18 GMT Hi, Greg,
You might enjoy testing character values with this tool:
http://www.geocities.com/SiliconValley/Vista/2013/charset/CharCode.html
Regards,
Lesley Regan Detroit
 Signature
> Helmut, > [quoted text clipped - 5 lines] > Perhaps the answer is that you can't determine the ASCII character of a > symbol that is not part of the ASCII set. Helmut Weber - 22 May 2006 20:54 GMT Hi Greg,
>Perhaps the answer is that you can't determine the ASCII character of a >symbol that is not part of the ASCII set. very much so.
The ultimate authority, IMHO, is Klaus Linke. Whether decorative or unicode or farsi or east asian or right to left hebrew or arabic, if Klaus doesn't know, well, at least I don't.
 Signature Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
Dave Lett - 22 May 2006 16:49 GMT Hi Greg,
If a little knowledge is a dangerous thing, then I'm lethal, man, LETHAL.
ASCII and Unicode are different. ASCII limits you to 256 different characters; Unicode limits you to 65,536 different characters. Therefore, sometimes ASCII cannot support the symbol you really want to create. If you want to see what ASCII character you will insert when using Chr(pAsc), then have a look at the VBA help topic "Character Set (0 - 127)." So, the OP can see that if he uses Chr(117), then VBA will insert a lowercase "u."
HTH, Dave
> Dave, > [quoted text clipped - 20 lines] > knowledgeable with ASCII codes so therefore I don't know if I am coming > closer to answering the question or not ;-)
|
|
|