Results 1 to 10 of 10

Thread: Overflow?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242

    Overflow?

    in my code an error appears and says Overflow, i go into the de-bug thing and hover mouse over the variable "totalexp" and it says the value of it is "32767" but its not 32767.
    here is the codeim using:
    VB Code:
    1. totalexp = totalexp + winexp
    Lpeek

  2. #2
    Lively Member Supreme Cookie's Avatar
    Join Date
    Nov 2002
    Location
    A small box
    Posts
    109
    so before that set the code to read:

    VB Code:
    1. totalexp = 0

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242
    its not always going to be "0"
    Lpeek

  4. #4
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308
    Can you post some more code for us to see. May be variable is getting some value greater than its extreme limit, therefore , overflow is occuring.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242
    ok:
    VB Code:
    1. Private Function battlewon(done As Boolean)
    2.     If totalene <= 0 Then
    3.         gold = gold + wingold
    4.         totalexp = totalexp + winexp
    5.         If exp - winexp > 0 Then
    6.             lbltext.Caption = "You won the battle. Total EXP: " & winexp & ""
    7.             GoTo doneturn:
    8.         Else
    9.         Do While exp - winexp <= 0
    10.             winexp = winexp - exp
    11.             addon = needexp / 100
    12.             addon2 = addon * 11
    13.             needexp = needexp + addon2
    14.             exp = needexp
    15.             exp = exp - winexp
    16.             level = level + 1
    17.             finish (True)
    18.             If level >= 4 Then
    19.                 If level <= 10 Then
    20.                     maxhp = maxhp + 3
    21.                     maxmp = maxmp + 1
    22.                     fp = fp + 1
    23.                     dp = dp + 1
    24.                     GoTo addedstats:
    25.                 End If
    26.                 If level <= 13 Then
    27.                     maxhp = maxhp + 5
    28.                     maxmp = maxmp + 1
    29.                     fp = fp + 1
    30.                     dp = dp + 1
    31.                     GoTo addedstats:
    32.                 End If
    33.                 If level <= 18 Then
    34.                     maxhp = maxhp + 10
    35.                     maxmp = maxmp + 2
    36.                     If playerclass = "Wizard" Then
    37.                         maxmp = maxmp + 1
    38.                     End If
    39.                     If playerclass = "Warrior" Then
    40.                         fp = fp + 1
    41.                     End If
    42.                     If playerclass = "Soldier" Then
    43.                         dp = dp + 1
    44.                     End If
    45.                     fp = fp + 1
    46.                     dp = dp + 1
    47.                     GoTo addedstats:
    48.                 End If
    49.                 If level <= 22 Then
    50.                     maxhp = maxhp + 18
    51.                     maxmp = maxmp + 2
    52.                     If playerclass = "Wizard" Then
    53.                         maxmp = maxmp + 1
    54.                     End If
    55.                     If playerclass = "Warrior" Then
    56.                         fp = fp + 1
    57.                     End If
    58.                     If playerclass = "Soldier" Then
    59.                         dp = dp + 1
    60.                     End If
    61.                     fp = fp + 2
    62.                     dp = dp + 1
    63.                     GoTo addedstats:
    64.                 End If
    65.                 If level <= 28 Then
    66.                     maxhp = maxhp + 25
    67.                     maxmp = maxmp + 2
    68.                     If playerclass = "Wizard" Then
    69.                         maxmp = maxmp + 1
    70.                     End If
    71.                     fp = fp + 2
    72.                     dp = dp + 2
    73.                     GoTo addedstats:
    74.                 End If
    75.                 If level <= 35 Then
    76.                     maxhp = maxhp + 35
    77.                     maxmp = maxmp + 3
    78.                     fp = fp + 2
    79.                     dp = dp + 2
    80.                     GoTo addedstats:
    81.                 End If
    82.                 If level <= 42 Then
    83.                     maxhp = maxhp + 50
    84.                     maxmp = maxmp + 3
    85.                     fp = fp + 3
    86.                     dp = dp + 3
    87.                     GoTo addedstats:
    88.                 End If
    89.                 If level <= 50 Then
    90.                     maxhp = maxhp + 70
    91.                     maxmp = maxmp + 4
    92.                     If playerclass = "Wizard" Then
    93.                         maxmp = maxmp + 1
    94.                     End If
    95.                     If playerclass = "Warrior" Then
    96.                         fp = fp + 1
    97.                     End If
    98.                     If playerclass = "Soldier" Then
    99.                         dp = dp + 1
    100.                     End If
    101.                     fp = fp + 3
    102.                     dp = dp + 3
    103.                     GoTo addedstats:
    104.                 End If
    105.                 If level <= 60 Then
    106.                     maxhp = maxhp + 85
    107.                     maxmp = maxmp + 6
    108.                     If playerclass = "Wizard" Then
    109.                         maxmp = maxmp + 1
    110.                     End If
    111.                     fp = fp + 3
    112.                     dp = dp + 3
    113.                     GoTo addedstats:
    114.                 End If
    115.                 If level <= 75 Then
    116.                     maxhp = maxhp + 100
    117.                     maxmp = maxmp + 8
    118.                     If playerclass = "Wizard" Then
    119.                         maxmp = maxmp + 1
    120.                     End If
    121.                     If playerclass = "Warrior" Then
    122.                         fp = fp + 1
    123.                     End If
    124.                     If playerclass = "Soldier" Then
    125.                         dp = dp + 1
    126.                     End If
    127.                     fp = fp + 4
    128.                     dp = dp + 3
    129.                     GoTo addedstats:
    130.                 End If
    131.                 If level <= 88 Then
    132.                     maxhp = maxhp + 120
    133.                     maxmp = maxmp + 9
    134.                     If playerclass = "Wizard" Then
    135.                         maxmp = maxmp + 1
    136.                     End If
    137.                     fp = fp + 5
    138.                     dp = dp + 5
    139.                     GoTo addedstats:
    140.                 End If
    141.                 If level <= 98 Then
    142.                     maxhp = maxhp + 200
    143.                     maxmp = maxmp + 10
    144.                     fp = fp + 7
    145.                     dp = dp + 7
    146.                     GoTo addedstats:
    147.                 End If
    148.                 If level >= 99 Then
    149.                     GoTo addedstats:
    150.                 End If
    151.             End If
    152.             maxhp = maxhp + 2
    153. addedstats:
    154.             If level > 99 Then
    155.                 level = 99
    156.             End If
    157.             If maxhp > 9999 Then
    158.                 maxhp = 9999
    159.             End If
    160.             If curhp > maxhp Then
    161.                 curhp = maxhp
    162.             End If
    163.             If maxmp > 999 Then
    164.                 maxmp = 999
    165.             End If
    166.             If curmp > maxmp Then
    167.                 curmp = maxmp
    168.             End If
    169.             GoTo doneturn:
    170.             Loop
    171.         End If
    172. doneturn:
    173. done = False
    174. End If
    175. End Function
    (thats the whole function that that snippet of code was from.
    Lpeek

  6. #6
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Variables are set to zero by default, so a totalexp = 0 is unnecessary, and would reset the variable to zero on every pass. I doubt he wants that.

    Try doing a Debug.Print on winexp and see what you get.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242
    whats a Debug.Print?
    Lpeek

  8. #8
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    That tells the debugger to display the value of winexp. Basically it's the same thing as hovering over the variable itself. This is what I do because I don't always get the results of a variable just by hovering over it.

  9. #9
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Oh, there's another point I wanted to make:

    I notice that there's no variable declaration in your function; I'm assuming you've got this in the General Declarations section of your form?

    Also, it's good practice to put an Option Explicit in the first line of the General Declarations section. This forces all variables to be declared before they are used, and will save you a LOT of headaches in debugging and error tracking.

    After doing your Option Explicit, run your program. If it errors out with "Undeclared Variable" or something like that, put the following:

    VB Code:
    1. Dim totalexp As Long
    2. Dim winexp As Long

    Note the use of Long variables. It's good to use long variables in the kind of program you're developing. I am thinking that's why you're getting the Overflow error. Integers can only handle between the numbers -355 and 355, if I remember correctly. I have successfully worked with numbers way up in the millions with Long variables, so you really shouldn't get an overflow unless totalexp goes beyond that range.

  10. #10
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by hothead
    Integers can only handle between the numbers -355 and 355, if I remember correctly.
    Nope. Integer limits go from -32768 to 32767.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width