Mistake in the Asc() VB function?
Could you please tell why the Asc() function returns incorrect result?
Dim TestChar = Chr(128)
Dim CharInt = Asc(TestChar) ' this is a mistake on Windows 7 x64. Asc(TestChar) returns 136 inste开发者_Python百科ad of 128
I executed this code on another computer and the result was 128.
Thanks.
Your computer is using a different default code page.
The Asc
function uses the system's current ANSI code page.
The Chr
function simply casts the value to char
. (Unless it's > 255
)
I just tried this exact code on Windows 7 x64 with Visual Studio 2010 and got the expected value of 128. I tried mixing options (Infer, explicit, etc ...) and the value remains the same. Can you provide some more details to help track this down?
Sub Main()
Dim TestChar = Chr(128)
Dim CharInt = Asc(TestChar)
Console.WriteLine(CharInt)
Stop
End Sub
The problem was that I used the different default code page. I changed it into the English and code works fine. Thank you!
精彩评论