Skip to main content
GameDev.net gamedev.net
🔒 Locked

OverFlow in VB

Started by Wizzy May 12, 2003 at 7:33 PM 5 replies 350+ views
Original Post
Wizzy
Wizzy
ok... i''m working on a part in my game that reads from a file and puts the info into variables... but i get this stupid overflow error 6 every time... and there isn''t a problem... it happens on line 3 of the "input #" - and i checked variable data types - and the data going in - and it''s fine... i have 9 variables on that line. here are the variables - datatype - and values going in... can anyone see a problem? Playerstat23-Byte-6 Playerstat24-Byte-27 Playerstat25-Integer-1980 Playerstat26-Byte-22 Playerstat27-Byte-5 Playerstat28-Byte-10 Playerstat29-Integer-190 Playerstat30-Long-500000 Playerstat31-Byte-4 as far as i know - ALL of that is legal... so what the hell is VB talking about?
Wizzy
Wizzy
i'll be more specific...

here's the code for reading the info


      
X = 1
Open ("c:\NBAManager1\players.txt") For Input As #1
Do While Not EOF(1)

Input #1, PlayerStat1(X), PlayerStat2(X), PlayerStat3(X), PlayerStat4(X), PlayerStat5(X), PlayerStat6(X), PlayerStat7(X), PlayerStat8(X), PlayerStat9(X), PlayerStat10(X), PlayerStat11(X), PlayerStat12(X)
Input #1, PlayerStat13(X), PlayerStat14(X), PlayerStat15(X), PlayerStat16(X), PlayerStat17(X), PlayerStat18(X), PlayerStat19(X), PlayerStat20(X), PlayerStat21(X), PlayerStat22(X)
Input #1, PlayerStat23(X), PlayerStat24(X), PlayerStat25(X), PlayerStat26(X), PlayerStat27(X), PlayerStat28(X), PlayerStat29(X), PlayerStat30(X), PlayerStat31(X)
Input #1, PlayerStat32(X), PlayerStat33(X), PlayerStat34(X), PlayerStat35(X), PlayerStat36(X), PlayerStat37(X)
Input #1, PlayerStat38(X), PlayerStat39(X), PlayerNumber(X)
Input #1, PlayerName(X)
Input #1, PlayerStat40(X), PlayerStat41(X), PlayerStat42(X), PlayerStat43(X), PlayerStat44(X), PlayerStat45(X), PlayerStat46(X)
X = X + 1

Loop

Close #1


here are the declarations

  

Global PlayerStat1(1000) As Byte
Global PlayerStat2(1000) As Byte
Global PlayerStat3(1000) As Byte
Global PlayerStat4(1000) As Byte
Global PlayerStat5(1000) As Byte
Global PlayerStat6(1000) As Byte
Global PlayerStat7(1000) As Byte
Global PlayerStat8(1000) As Byte
Global PlayerStat9(1000) As Byte
Global PlayerStat10(1000) As Byte
Global PlayerStat11(1000) As Byte
Global PlayerStat12(1000) As Byte
Global PlayerStat13(1000) As Byte
Global PlayerStat14(1000) As Byte
Global PlayerStat15(1000) As Byte
Global PlayerStat16(1000) As Byte
Global PlayerStat17(1000) As Byte
Global PlayerStat18(1000) As Byte
Global PlayerStat19(1000) As Byte
Global PlayerStat20(1000) As Byte
Global PlayerStat21(1000) As Byte
Global PlayerStat22(1000) As Byte
Global PlayerStat23(1000) As Byte
Global PlayerStat24(1000) As Byte
Global PlayerStat25(1000) As Integer
Global PlayerStat26(1000) As Byte
Global PlayerStat27(1000) As Byte
Global PlayerStat28(1000) As Byte
Global PlayerStat29(1000) As Integer
Global PlayerStat30(1000) As Long
Global PlayerStat31(1000) As Byte
Global PlayerStat32(1000) As Integer
Global PlayerStat33(1000) As Byte
Global PlayerStat34(1000) As Byte
Global PlayerStat35(1000) As Byte
Global PlayerStat36(1000) As Byte
Global PlayerStat37(1000) As Byte
Global PlayerStat38(1000) As Byte
Global PlayerStat39(1000) As Byte
Global PlayerStat40(1000) As Integer
Global PlayerStat41(1000) As Integer
Global PlayerStat42(1000) As Single
Global PlayerStat43(1000) As Integer
Global PlayerStat44(1000) As Integer
Global PlayerStat45(1000) As Integer
Global PlayerStat46(1000) As Integer
Global PlayerStat47(1000) As Byte
Global PlayerStat48(1000) As Byte
Global PlayerStat49(1000) As Byte
Global PlayerStat50(1000) As Byte
Global PlayerNumber(1000) As Integer
Global PlayerName(1000) As String


here's the file - i made one entry to test it - and it's not working

  

91 82 61 95 84 95 71 85 71 95 84 99
91 89 90 81 8 26 1 0 1
6 27 1980 22 5 10 190 500000 4
2001 1 1 26 26 2
84 0 1
Jay Booth
82 75 23.4 48 75 84 18



[edited by - Wizzy on May 12, 2003 8:38:17 PM]
Ready4Dis
Ready4Dis
Firstly...

Why not do it like this:

global PlayerStats(50, 1000) as integer
global PlayerNumber(1000) as integer
global PlayerName(1000) as string

Make sure you only read values between 0 and 255 into a byte, you may be reading something incorrect. If you use all integers like my method, you don''t have to worry about it, and it REALLY simplifies reading them in.


  
Dim ctr as integer, ct2 as integer

ctr = 1
ct2 = 1

do until eof(1)
for ct2 = 1 to 39
input #1, PlayerStats(ct2,ctr)
next ct2
input #1, PlayerNumber(ctr)
input #1, PlayerName(ctr)
for ct2 = 40 to 46
input #1, PlayerStats(ct2,ctr)
next ct2
ctr = ctr + 1
loop
Ready4Dis
Ready4Dis
By the way... value # 24 is > 255, which overflows the PlayerStats24 byte, hence the error.
Wizzy
Wizzy
thanx, that fixed it... i was missing a number in the player file :\ didn''t notice that

and i''ll try that Playerstat (50,1000)... cause i''m gunna have a lot more stats... so that would be useful.. i actually didn''t know you could do it like that.
BlueMonk
BlueMonk
quote:
Original post by Wizzy
thanx, that fixed it... i was missing a number in the player file :\ didn''t notice that

and i''ll try that Playerstat (50,1000)... cause i''m gunna have a lot more stats... so that would be useful.. i actually didn''t know you could do it like that.


Since you seem to know ahead of time what the different player stats mean (seeing as how you have given them different and specific data types) would suggest an alternative because naming your variables simply after numbers is very messy and hard to deal with. I would recomment creating a user-defined type. This would result in far more efficient file storage and file access (they would be stored in binary format). It will mean you can''t view the file in notepad, but I think the benefits far outwiegh the costs:


Private Type PlayerStats_t
Name As String
X As Integer
Y As Integer
HP As Integer
MaxHP As Integer
Keys As Byte
Grenades As Byte
Level As Byte
Group As Byte
End Type

Dim PlayerStats(100) As PlayerStats_t

Private Sub FileIODemo()
Dim PlayerCount As Integer

With PlayerStats(0)
.Name = "Ben"
.X = 1000
.Y = 1234
.HP = 500
.MaxHP = 500
.Keys = 0
.Grenades = 3
.Level = 1
.Group = 0
End With

With PlayerStats(1)
.Name = "Joeseph"
.X = 3141
.Y = 5926
.HP = 456
.MaxHP = 650
.Keys = 1
.Grenades = 7
.Level = 2
.Group = 1
End With

PlayerCount = 2

'' Write some data
Open App.Path & "\MyFile.dat" For Binary Access Write As #1
Put #1, , PlayerCount
Put #1, , PlayerStats(0)
Put #1, , PlayerStats(1)
Close #1

'' Read it back into subsequent elements
Open App.Path & "\MyFile.dat" For Binary Access Read As #1
Get #1, , PlayerCount
Get #1, , PlayerStats(2)
Get #1, , PlayerStats(3)
Close #1

End Sub


"All you need to do to learn circular logic is learn circular logic"
"All you need to do to learn circular logic is learn circular logic"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.