Results 1 to 6 of 6

Thread: [2008] Read from file into array fails at line 134

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    [2008] Read from file into array fails at line 134

    I can't figure out why it works all the way up to line 134 and then all of a sudden spits out an error..

    Here is the code:

    Code:
           
            Dim tempstr As String
            Dim lvlarray(200) As Integer
            Dim xparray(200) As Integer
            Dim x As Integer = 1
            Dim firstcomma As Integer
            Dim filenum As Integer = FreeFile()
            FileOpen(filenum, "C:\lvl-xp.txt", OpenMode.Input)
            Do While Not EOF(1)
                tempstr = LineInput(filenum)
                firstcomma = tempstr.IndexOf(",")
                lvlarray(x) = tempstr.Substring(0, firstcomma)
                xparray(x) = tempstr.Substring(lvlarray(x).ToString.Length + 1, tempstr.Length - lvlarray(x).ToString.Length - 1)
                'MsgBox("lvl:" & lvlarray(x) & " xp:" & xparray(x))
                x += 1
            Loop
    I know it's messy and is probably not the best way of doing it, but for now, it works (kinda).

    Here is the txt file that I'm reading from:

    Code:
    1,0
    2,1000
    3,5700
    4,15900
    5,33000
    6,58100
    7,92600
    8,137400
    9,193700
    10,262450
    11,344700
    12,441442
    13,553700
    14,682500
    15,828700
    16,993480
    17,1177700
    18,1382400
    19,1608300
    20,1857000
    21,2128800
    22,2425300
    23,2746900
    24,3095000
    25,3478100
    26,3875000
    27,4308700
    28,4772900
    29,5268700
    30,5797100
    31,6359000
    32,6956000
    33,7589000
    34,8257800
    35,8965000
    36,9711600
    37,10498000
    38,11325300
    39,12195200
    40,13108000
    41,14066000
    42,15069000
    43,16119300
    44,17217500
    45,18377000
    46,19602000
    47,20896000
    48,22262000
    49,23704000
    50,25227500
    51,26835000
    52,28531000
    53,30320000
    54,32208000
    55,34199000
    56,36298000
    57,38518000
    58,40844000
    59,43297000
    60,45882500
    61,48604500
    62,51471000
    63,54483000
    64,57650500
    65,60981000
    66,64483000
    67,68159000
    68,72020000
    69,76074000
    70,80320000
    71,84788000
    72,89459000
    73,94360000
    74,99485226
    75,104858697
    76,110489000
    77,116368095
    78,122525000
    79,128858000
    80,135683000
    81,142714000
    82,150048000
    83,157700981
    84,165691091
    85,174219116
    86,183314046
    87,193005738
    88,203324924
    89,214303219
    90,225973131
    91,238369000
    92,251523000
    93,265472000
    94,280253000
    95,295900000
    96,312452000
    97,329950000
    98,348435000
    99,367940200
    100,388515000
    101,410200000
    102,433039000
    103,457078000
    104,482360000
    105,508933000
    106,536847000
    107,566146000
    108,596884000
    109,629114000
    110,662878000
    111,698236000
    112,735240000
    113,773954000
    114,814418000
    115,856700000
    116,900856000
    117,946944000
    118,995025000
    119,1045164000
    120,1097414000
    121,1151839000
    122,1208532000
    123,1267520000
    124,1328891000
    125,1394766000
    126,1465353000
    127,1540775000
    128,1621343000
    129,1707202000
    130,1798604000
    131,1895689000
    132,1998700000
    133,2107964000
    134,2223594548
    135,2345859740
    136,2474996700
    137,2611246919
    138,2754856329
    139,2906075326
    140,3065158798
    141,3232366145
    142,3407961306
    143,3592212780
    144,3785393657
    145,3999725569
    146,4236116170
    147,4495490778
    148,4778792472
    149,5086982188
    150,5421038816
    151,5781959301
    152,6170758735
    153,6588470454
    154,7036146133
    155,7514855881
    156,8025688337
    157,8569750762
    158,9148169131
    159,9762088230
    160,10412671747
    161,11101102362
    162,11828581842
    163,12596331130
    164,13405591808
    165,14323751218
    166,15355130652
    167,16504312961
    168,17775189762
    169,19172880438
    170,20701812509
    171,22366681987
    172,24172261748
    173,26123401888
    174,28225030084
    175,30482151954
    176,32899851410
    177,35483291016
    178,38237712340
    179,41168436309
    180,44280863558
    181,47580474776
    182,51072831062
    183,54763574263
    184,58658427326
    185,63115894897
    186,68115894897
    187,73800275488
    188,80068783764
    189,86983099850
    190,94564821930
    191,102835870903
    192,111818491760
    193,121535254947
    194,132009057736
    195,144873495079
    196,160214619412
    197,178119779264
    198,198677624721
    199,221978112873
    200,248292513235

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2008] Read from file into array fails at line 134

    What's the error message?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Read from file into array fails at line 134

    Arithmetic operation resulted in an overflow.

    Make sure you are not dividing by zero.



    EDIT: Also shows in the bottom window

    A first chance exception of type 'System.OverflowException' occurred in Microsoft.VisualBasic.dll

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2008] Read from file into array fails at line 134

    Oh, of course, a signed integer has a maximum size of 2 billion and some change. You exceed that value on line 134. Line 133 is 2 billion and not enough extra, while line 134 is 2 billion and too much extra.

    The solution is also simple. Those arrays need to be declared as Long rather than Integer.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Read from file into array fails at line 134

    Oh wow..can't believe I didn't think of that.

    Thanks a bunch!

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2008] Read from file into array fails at line 134

    Don't feel bad about that, I actually looked for that type of thing, but didn't see it until you posted the error message.
    My usual boring signature: Nothing

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