Author |
Message |
john goslin #1 / 7
|
 Am I that stupid ?
I have a program which does the equivalent of the following: Public Function Overflow() Dim Y as long, X as integer X = 45 Y = X * 1000 End Function On the final line, I get an Overflow error. The error does not occur if X is declared as Long. This happens in both Access 97 and Access 2. The way I used to see it (before today's miraculous revelation) was that if Y was declared as Long, then everything should be fine. But seemingly, VBA assigns the result of (X * 1000) to X itself (or to a temporary variable analogous to X) before assigning it to Y and then resetting X to what it originally was (else why would declaring X as Long avoid the error!). The consequence of this seems to be that you can never multiply any integer variable by any other variable or constant if there is any risk of the result being greater than 32000! This seems utterly stupid to me. But maybe I've just been missing something all these years! Any comments please. Is this really how it's supposed to be? Incidentally, try typing "? 42 * 1000" into the debug window - at least the error message there is forgivable! John Gosling
|
Sat, 11 Oct 2003 21:58:35 GMT |
|
 |
Ananda Si #2 / 7
|
 Am I that stupid ?
Hi John, You don't want us to reply to the subject line <grin> Quote: > Incidentally, try typing "? 42 * 1000" into the debug window - at least the > error message there is forgivable!
You do need to follow instructions once in a while and press the "Help" button in the error message dialog. In Access 2000, Help states: You attempt to use a number in a calculation, and that number is coerced into an integer, but the result is larger than an integer. For example: Dim x As Long x = 2000 * 365 ' Error: Overflow To work around this situation, type the number, like this: Dim x As Long x = CLng(2000) * 365 Ananda http://go.to/ananda
|
Sat, 11 Oct 2003 22:40:16 GMT |
|
 |
John Spence #3 / 7
|
 Am I that stupid ?
No, you're not that stupid. Or if you are can I join the club. Looks as if I'm going to have to declare all my integer variables as longs, if I ever need to do any arithmetic with them that could yield a result that might go out of range for an integer. Bother!!!!! There I was -- so content with the world. Quote:
> Hi John, > You don't want us to reply to the subject line <grin> > > Incidentally, try typing "? 42 * 1000" into the debug window - at least > the > > error message there is forgivable! > You do need to follow instructions once in a while and press the "Help" > button in the error message dialog. In Access 2000, Help states: > You attempt to use a number in a calculation, and that number is coerced > into an integer, but the result is larger than an integer. For example: > Dim x As Long > x = 2000 * 365 ' Error: Overflow > To work around this situation, type the number, like this: > Dim x As Long > x = CLng(2000) * 365 > Ananda > http://go.to/ananda
|
Sat, 11 Oct 2003 23:48:59 GMT |
|
 |
Dirk Goldga #4 / 7
|
 Am I that stupid ?
It behaves the way I would expect, anyway, though I agree it would be nice if it considered the data type of the target of the assignment, not just the values participating in the expression. For what it's worth, you can get around this problem -- if you anticipate it -- by writing your expression as Y = X * 1000& thus forcing the numeric constant to a Long. -- Dirk Goldgar (remove NOSPAM from reply address)
Quote: > I have a program which does the equivalent of the following: > Public Function Overflow() > Dim Y as long, X as integer > X = 45 > Y = X * 1000 > End Function > On the final line, I get an Overflow error. The error does not occur if X > is declared as Long. This happens in both Access 97 and Access 2. > The way I used to see it (before today's miraculous revelation) was that if > Y was declared as Long, then everything should be fine. But seemingly, VBA > assigns the result of (X * 1000) to X itself (or to a temporary variable > analogous to X) before assigning it to Y and then resetting X to what it > originally was (else why would declaring X as Long avoid the error!). > The consequence of this seems to be that you can never multiply any integer > variable by any other variable or constant if there is any risk of the > result being greater than 32000! > This seems utterly stupid to me. But maybe I've just been missing something > all these years! Any comments please. Is this really how it's supposed to > be? > Incidentally, try typing "? 42 * 1000" into the debug window - at least the > error message there is forgivable! > John Gosling
|
Sat, 11 Oct 2003 23:46:31 GMT |
|
 |
john goslin #5 / 7
|
 Am I that stupid ?
Thanks for the reply, Ananda. As it happens, Access 97 Help hasn't yet caught up with Access 2000 Help on this issue and leads you to believe that the only crucial issue is the data type of the variable being assigned to ! John
Quote: > Hi John, > You don't want us to reply to the subject line <grin> > > Incidentally, try typing "? 42 * 1000" into the debug window - at least > the > > error message there is forgivable! > You do need to follow instructions once in a while and press the "Help" > button in the error message dialog. In Access 2000, Help states: > You attempt to use a number in a calculation, and that number is coerced > into an integer, but the result is larger than an integer. For example: > Dim x As Long > x = 2000 * 365 ' Error: Overflow > To work around this situation, type the number, like this: > Dim x As Long > x = CLng(2000) * 365 > Ananda > http://go.to/ananda
|
Sun, 12 Oct 2003 22:07:31 GMT |
|
 |
Jeff #6 / 7
|
 Am I that stupid ?
I noticed that all of the conversion functions return Type Mismatch in Access 97 Have you found any solutions to doing conversions? ie. sMyVar as String vMyVar as Variant vMyVar = CVar(sMyVar) returns Type Mismatch error. Quote: -----Original Message----- No, you're not that stupid. Or if you are can I join the club. Looks as if I'm going to have to declare all my integer variables as longs, if I ever need to do any arithmetic with them that could yield a result that might go out of range for an integer. Bother!!!!! There I was -- so content with the world.
> Hi John, > You don't want us to reply to the subject line <grin> > > Incidentally, try typing "? 42 * 1000" into the debug window - at least > the > > error message there is forgivable! > You do need to follow instructions once in a while and press the "Help" > button in the error message dialog. In Access 2000, Help states: > You attempt to use a number in a calculation, and that number is coerced > into an integer, but the result is larger than an integer. For example: > Dim x As Long > x = 2000 * 365 ' Error: Overflow > To work around this situation, type the number, like this: > Dim x As Long > x = CLng(2000) * 365 > Ananda > http://go.to/ananda .
|
Tue, 21 Oct 2003 20:12:48 GMT |
|
 |
John Spence #7 / 7
|
 Am I that stupid ?
Jeff, assuming that you are trying to start a new thread. Access 97 and declaring my variables. I don't get the error. Function testing() Dim sMyVar As String, vMyVar As Variant vMyVar = CVar(sMyVar) End Function The above generates no errors for me. Quote:
> I noticed that all of the conversion functions return Type Mismatch in Access 97 > Have you found any solutions to doing conversions? > ie. > sMyVar as String > vMyVar as Variant > vMyVar = CVar(sMyVar) returns Type Mismatch error. > -----Original Message----- > No, you're not that stupid. Or if you are can I join the club. > Looks as if I'm going to have to declare all my integer variables as longs, if I > ever need to do any arithmetic with them that could yield a result that might go > out of range for an integer. > Bother!!!!! There I was -- so content with the world.
> > Hi John, > > You don't want us to reply to the subject line <grin> > > > Incidentally, try typing "? 42 * 1000" into the debug window - at least > > the > > > error message there is forgivable! > > You do need to follow instructions once in a while and press the "Help" > > button in the error message dialog. In Access 2000, Help states: > > You attempt to use a number in a calculation, and that number is coerced > > into an integer, but the result is larger than an integer. For example: > > Dim x As Long > > x = 2000 * 365 ' Error: Overflow > > To work around this situation, type the number, like this: > > Dim x As Long > > x = CLng(2000) * 365 > > Ananda > > http://go.to/ananda > .
|
Wed, 22 Oct 2003 00:19:06 GMT |
|
|
|