Is there a limit on a integer variable (overflow error) 
Author Message
 Is there a limit on a integer variable (overflow error)

Hi all,

I have the code below which updates a field.

The code causes an overflow error when prevID  gets to somewhere
around 32000.

If I change the variable type from INteger to Double or Long the code
runs without error bu the fields("parent") is not updated with PrevID
and remains blank from then to EOF.

Any Ideas

Thanks

Jason.

Sub CreateBC()
Dim db As Database
Dim rs As Recordset
Dim prevID As Integer  'This is the bit that causes an overflow error

Set db = CurrentDb  'Sets the db as the default current db
Set rs = db.OpenRecordset("Permissions")

With rs
      .Move 1
      'prevID = 1
      prevID = .Fields("ID")
      While Not .EOF

            If .Fields("ID") <> .Fields("Parent") Then
                    .Edit
                    .Fields("Parent") = prevID
                    .Update
            prevID = .Fields("parent")

            Else

            prevID = .Fields("ID")

           End If

     .MoveNext
     Wend
End With
rs.Close

End Sub



Sun, 14 Nov 2004 08:40:45 GMT  
 Is there a limit on a integer variable (overflow error)
Certainly there's a limit on Integer variables: 32767.  Obviously the ID
field in table/query Permissions is defined as a larger size;  probably
Long.  You should declare prevID as the same data type.

As for why your code isn't working right, have you tried stepping through
it, checking the values of variables and fields as you go, to see what
happens?  One thing that looks suspect on first glance is here:

Quote:
>             If .Fields("ID") <> .Fields("Parent") Then
>                     .Edit
>                     .Fields("Parent") = prevID
>                     .Update
>             prevID = .Fields("parent")

where the upshot of the code would seem to leave prevID unchanged, since you
assign its value to .Fields("Parent") and then assign that value back to
prevID again.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Quote:
> Hi all,

> I have the code below which updates a field.

> The code causes an overflow error when prevID  gets to somewhere
> around 32000.

> If I change the variable type from INteger to Double or Long the code
> runs without error bu the fields("parent") is not updated with PrevID
> and remains blank from then to EOF.

> Any Ideas

> Thanks

> Jason.

> Sub CreateBC()
> Dim db As Database
> Dim rs As Recordset
> Dim prevID As Integer  'This is the bit that causes an overflow error

> Set db = CurrentDb  'Sets the db as the default current db
> Set rs = db.OpenRecordset("Permissions")

> With rs
>       .Move 1
>       'prevID = 1
>       prevID = .Fields("ID")
>       While Not .EOF

>             If .Fields("ID") <> .Fields("Parent") Then
>                     .Edit
>                     .Fields("Parent") = prevID
>                     .Update
>             prevID = .Fields("parent")

>             Else

>             prevID = .Fields("ID")

>            End If

>      .MoveNext
>      Wend
> End With
> rs.Close

> End Sub



Sun, 14 Nov 2004 08:56:26 GMT  
 Is there a limit on a integer variable (overflow error)
by definition, integers only go to 32767 (or is it 32768?)

anyhow, let's say 32,000.    You need to redesign any fields or
variables to take this into account.  Move to Long Integer which goes
to 2 billion


Quote:
>Hi all,

>I have the code below which updates a field.

>The code causes an overflow error when prevID  gets to somewhere
>around 32000.

>If I change the variable type from INteger to Double or Long the code
>runs without error bu the fields("parent") is not updated with PrevID
>and remains blank from then to EOF.

----------------
Richard "ManxMan" Killey

www.comeandread.com/access

visit my site for tips



Sun, 14 Nov 2004 21:14:19 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Long = Integer * Integer Overflow error

2. Error occurs when using integer variable instead of number

3. Overflow exceptions when converting from Long to Integer?

4. Integer overflow traps

5. unsigned 32 bits integer arithmetic / overflow

6. ATT: Math wizards. Bit manipulations and integer overflow

7. HELP: Integer -> Hex conversion (Overflow)

8. Overflow - Am I going crazy?

9. Listbox Index limited to Integer

10. Error handling / Arithmetic overflow error

11. Overflow error, error number 6, in VB6 using Crystal Reports 7

12. Cause of error (error 6 overflow) in Windows 2000

 

 
Powered by phpBB® Forum Software