Re: how to get Unicode char value? by Alex
Alex
Mon Dec 29 22:09:14 CST 2003
Ok, so you actually want to extract the code for a character? I was thrown
off by the discussion of getting nothing back in the MsgBox and the fact
that your original code extract as written returns a character, not a
numeric code.
The code you show immediately below doesn't look like VBA or VBScript (looks
like a typecase from C), so I assume we need to go back and look at this
bit:
ch = ChrW(MyObject.Characters(1))
I don't know much about Microsoft Word, but I assume that MyObject
represents a word from the context, and Characters(1) is the first letter in
the word.
In that case, it is an actual letter, not a character code already - and the
problem is that ChrW is supposed to take a _character code_ and return a
character!
You want something like this, instead:
ch = AscW(MyObject.Characters(1))
dilbir wrote:
> Hi,
> I can see Arabic characters correctly in WORD. I want to make
> VBSCript macro for MS WORD, in macro I want to process arabic
> characters data numerically. I get arabic words in a list but don't
> know how to get numerical value of UNICODE in VbScript. Can you see
> following code & suggest how can I get numeric value of unicode char.
>
>
> For Each MyObject In MyCollection ' Iterate through each element.
> MsgBox MyObject.Text
> ch = (LONG)MyObject.Characters(1) ' here I want UNICODE char
> value
> MsgBox ch
> Next
>
> Regards
>
> Dilbir
>
> "Alex K. Angelopoulos [Server MVP]" <aka-at-mvps-dot-org> wrote in
> message news:<e5Ka$edzDHA.2872@TK2MSFTNGP09.phx.gbl>...
>> It sounds to me like you're viewing in a non-Unicode font.
>>
>> Could you try this, please? Run the following short VBScript and see
>> if you get Arabic characters displayed. If they come back as
>> blocks/questionmarks, we know that the characters aren't there in the
>> default system font.
>>
>> I don't know for certain what the fix is - it may depend on the PC's
>> operating system. For what it's worth, I have no problems with Arabic
>> character display on my North American version of Windows XP Pro SP1...
>>
>> for i = 1569 to 1594
>> s = s & ChrW(i)
>> next
>> MsgBox s
>>
>>
>>
>> dilbir wrote:
>>> Hi,
>>> I am writing VBScript for an arbic page, for this I have to know what
>>> character value is then I have to replace character with some numeric
>>> value. but with following code I can't get UNICODE char value instead
>>> i get '?'
>>> for e.g
>>> for char 'A' i nead value 65
>>> for first arabic char i nead value in script 0627..
>>>
>>> Any help will be appriciated ...
>>>
>>> Dim Found, MyObject, MyCollection
>>> Selection.HomeKey Unit:=wdStory
>>> Selection.EndKey Unit:=wdLine, Extend:=wdExtend
>>> Set MyCollection = Selection.Words
>>> MsgBox "This line has " & MyCollection.Count
>>> For Each MyObject In MyCollection ' Iterate through each element.
>>> MsgBox MyObject.Text
>>> ch = ChrW(MyObject.Characters(1))
>>> Next
>>>
>>>
>>> regards
>>>
>>> dilbir