Error in VB Asc () function?

Could you explain why the Asc () function returns an incorrect result?

Dim TestChar = Chr(128) Dim CharInt = Asc(TestChar) ' this is a mistake on Windows 7 x64. Asc(TestChar) returns 136 instead of 128 

I ran this code on another computer and the result was 128.

Thanks.

+4
source share
3 answers

Your computer uses a different default code page.

The Asc function uses the current ANSI code page.
The Chr function simply distinguishes the char value. (If it is not > 255 )

+12
source

I just tried this exact code on Windows 7 x64 with Visual Studio 2010 and got the expected value of 128. I tried the mix options (Infer, explicit, etc ...) and the value remains the same. Can you provide more details to track this?

 Sub Main() Dim TestChar = Chr(128) Dim CharInt = Asc(TestChar) Console.WriteLine(CharInt) Stop End Sub 
+2
source

The problem was that I was using a different default code page. I changed it to English and the code works fine. Thanks!

+1
source

Source: https://habr.com/ru/post/1311753/


All Articles