VBS Sign Extending Variables Incorrectly? 
Author Message
 VBS Sign Extending Variables Incorrectly?

Does anyone know why this happens?

x = &H8000
MsgBox(x) - Displays as &HFFFF8000 (-32768) WRONG!

y = 32768
MsgBox(y) - Displays as &H8000 (32768) Correct!

Both x and y are the same number yet if you display x and y in a msgbox you
get different results!

What's the difference between Hex representation and decimal?

Any insight would be greatly appreciated.

Fabian



Mon, 21 Jul 2003 10:04:02 GMT  
 VBS Sign Extending Variables Incorrectly?
A 1- to 4-digit hex number is treated as a 2-byte signed integer by
default. That's why it comes out negative. A 5- to 8-digit hex number is
treated as a 4-byte signed integer. Use the & suffix to force shorted hex
strings to be treated as 4-byte signed numbers.  e.g. x = &H8000&

Joshua Lee
Microsoft



Sat, 06 Sep 2003 04:36:45 GMT  
 VBS Sign Extending Variables Incorrectly?
Joshua,

You do realize that this is *not* mentioned anywhere in the VBScript documentation.  People with
full VB background might *guess* that VBScript supports this.

It's just like the endless stream of questions about "how do I include a "" in a string" :-)...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> A 1- to 4-digit hex number is treated as a 2-byte signed integer by
> default. That's why it comes out negative. A 5- to 8-digit hex number is
> treated as a 4-byte signed integer. Use the & suffix to force shorted hex
> strings to be treated as 4-byte signed numbers.  e.g. x = &H8000&

> Joshua Lee
> Microsoft



Sat, 06 Sep 2003 06:04:45 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Signed variables?

2. sign a *.vbs file

3. signing a .vbs script file?

4. Sign html form with vbs

5. Have cert, but can't sign VBS

6. sign a *.vbs file

7. Anyone have experience with digitally signing vbs files?

8. Signing a VBS-Script

9. Signing a vbs script

10. How to pass back variables from called vbs from vbs using wsh

11. passing variable to vbs program (WSH)

12. What are the variable limits in VBS?

 

 
Powered by phpBB® Forum Software