473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

This is weird...

Look at the code below. All three variables are initialized to the same
value, -9223372036854775808. The first two work OK but the third throws a
overflow error. Why? (Framework v1.0.3705)

'-- OK, no overflow
Dim i as Long = Long.MinValue
Dim k as Long = CLng(-2 ^ 63)

'-- Overflow error
Dim m as Long = -9223372036854775808
Nov 20 '05 #1
8 1072

"Brian" <no****@prairie.lakes.com> escreveu na mensagem
news:vo************@corp.supernews.com...
Look at the code below. All three variables are initialized to the same
value, -9223372036854775808. The first two work OK but the third throws a
overflow error. Why? (Framework v1.0.3705)

'-- OK, no overflow
Dim i as Long = Long.MinValue
Dim k as Long = CLng(-2 ^ 63)

'-- Overflow error
Dim m as Long = -9223372036854775808


You should add the literal type charecter 'L'.
Something like -9223372036854775808L
----
Rafael Pivato
Nov 20 '05 #2
Nope, already tried to append the L.
"Rafael Pivato" <rp*****@cpovo.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

"Brian" <no****@prairie.lakes.com> escreveu na mensagem
news:vo************@corp.supernews.com...
Look at the code below. All three variables are initialized to the same
value, -9223372036854775808. The first two work OK but the third throws a overflow error. Why? (Framework v1.0.3705)

'-- OK, no overflow
Dim i as Long = Long.MinValue
Dim k as Long = CLng(-2 ^ 63)

'-- Overflow error
Dim m as Long = -9223372036854775808


You should add the literal type charecter 'L'.
Something like -9223372036854775808L
----
Rafael Pivato

Nov 20 '05 #3
The 1st example returns a Long that is well in range.
The 2nd example tries to convert the number to long since you explicitly
told it to do so using CLng(operation). The computer doesn't try figure
out exact value at compile time and because you told it to use CLng() to
change whatever number resulted into a long it assumes you know what you
are doing so it doesn't complain.
The 3nd example is obvious to the compiler the number you typed in will
never behave as the value as it is entered so it's an error.

Nov 20 '05 #4
"Rafael Pivato" <rp*****@cpovo.net> schrieb

"Brian" <no****@prairie.lakes.com> escreveu na mensagem
news:vo************@corp.supernews.com...
Look at the code below. All three variables are initialized to the
same value, -9223372036854775808. The first two work OK but the
third throws a overflow error. Why? (Framework v1.0.3705)

'-- OK, no overflow
Dim i as Long = Long.MinValue
Dim k as Long = CLng(-2 ^ 63)

'-- Overflow error
Dim m as Long = -9223372036854775808


You should add the literal type charecter 'L'.
Something like -9223372036854775808L


Also doesn't work here (VB 2003). Seems to be a code editor bug.
This works: m = &H8000000000000000
--
Armin

Nov 20 '05 #5
"Ting Liang (MSFT)" <tl****@online.microsoft.com> schrieb
Dim m as Long = -9223372036854775808

The 3nd example is obvious to the compiler the number you typed in
thirdond? ;-)
will never behave as the value as it is entered so it's an error.


Isn't it a Long literal within the valid range for Long literals?

Seem to be still the same code editor programmers like for VB6: Try this in
VB6:

Dim l As Long
l = -2147483648&

It also doesn't work.

*LOL*

--
Armin

Nov 20 '05 #6
hmmmmmm...

I think that the compiler misunderstood.

He is trying to make negative the absolute value, which is an overflow for
Long.

In this case you should use the hexadecimal literal 0x8000000000000000
(&H8000000000000000 in VB)

---

Rafael Pivato

"Brian" <no****@prairie.lakes.com> escreveu na mensagem
news:vo************@corp.supernews.com...
Nope, already tried to append the L.
"Rafael Pivato" <rp*****@cpovo.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

"Brian" <no****@prairie.lakes.com> escreveu na mensagem
news:vo************@corp.supernews.com...
Look at the code below. All three variables are initialized to the same value, -9223372036854775808. The first two work OK but the third
throws
a overflow error. Why? (Framework v1.0.3705)

'-- OK, no overflow
Dim i as Long = Long.MinValue
Dim k as Long = CLng(-2 ^ 63)

'-- Overflow error
Dim m as Long = -9223372036854775808


You should add the literal type charecter 'L'.
Something like -9223372036854775808L
----
Rafael Pivato


Nov 20 '05 #7
tl****@online.microsoft.com (Ting Liang (MSFT)) scripsit:
The 3nd example is obvious to the compiler the number you typed in will
never behave as the value as it is entered so it's an error.


I don't understand that. -9223372036854775807 is in the range of the
Long datatype. When specifying it in hex format, it will work.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #8
Thanks for all of your input. I found out the cause of this problem. If you
want to check it out yourself go to:

http://support.microsoft.com/default...b;en-us;820657

"Armin Zingler" <az*******@freenet.de> wrote in message
news:e%***************@TK2MSFTNGP12.phx.gbl...
"Rafael Pivato" <rp*****@cpovo.net> schrieb

"Brian" <no****@prairie.lakes.com> escreveu na mensagem
news:vo************@corp.supernews.com...
Look at the code below. All three variables are initialized to the
same value, -9223372036854775808. The first two work OK but the
third throws a overflow error. Why? (Framework v1.0.3705)

'-- OK, no overflow
Dim i as Long = Long.MinValue
Dim k as Long = CLng(-2 ^ 63)

'-- Overflow error
Dim m as Long = -9223372036854775808


You should add the literal type charecter 'L'.
Something like -9223372036854775808L


Also doesn't work here (VB 2003). Seems to be a code editor bug.
This works: m = &H8000000000000000
--
Armin

Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dominik B. | last post by:
I'm executing these commands: $text="example text"; $parts=explode(" ", $text); $result=$parts; $result becomes a weird array. echo "$result" prints 'example',
3
by: Betty Perea | last post by:
I'm having a little weird condition. I have a simple form (POST method), whose Action is a validation script, most of the times it works. But sometimes, the validation script does not "receive"...
1
by: Minti | last post by:
Hi there all, I am having a weird problem in the following Applet code, <begin code> public class MouseInputTester extends java.applet.Applet { private String msg = ""; private int mouseX ;...
5
by: python newbie | last post by:
hey, okay, I'm trying to figure out why my books: Quick Python, Python in a Nutshell, Python Cookbook and Learning Python don't say anything about the weird behavior of a list when you have one as...
2
by: holgeradelmann | last post by:
Can anyone help please: I found a nice article on the web how to write my dynamice information into an RSS-XML. But I cannot get the code to work. The problem is so simple but weird....
13
by: Wolfgang Kaml | last post by:
Hello All, I have been researching newsgroups and knowledgebase all morning and not found a solution that would solve the problem I have. I am having an ASP or ASPX web page that implement a...
0
by: LRW | last post by:
I manage our mySQL database through putty (SSH terminal client). And whenever I do a select * from the table that contains ENCODEd passwords, the funky characters do funky things with the display....
1
by: Ot | last post by:
I have two different solutions that use xml serialization to create xml from a given class. The class is defined identically in both solutions. I copied the code for both the class and the code...
0
by: Zwyatt | last post by:
having a really weird little bug w/ time_t...check it out: I have the following code (simplified here): #include <time.h> class A { public: char *aString; int aNum;
4
by: bbembi_de | last post by:
Hello everyone, I have a C# program that runs a batch from the command line. I use the following code for that: String arguments = "/C CALL batchfile.bat"; ProcessStartInfo startInfo = new...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.