[Gambas-user] integer / string file IO issue
Beren Scott
berenscott at ...1979...
Fri Jun 5 10:00:02 CEST 2009
I am sending the project source.
On Fri, 2009-06-05 at 09:40 +0200, Benoît Minisini wrote:
> > Dear users,
> >
> > I am having a strange issue in relation to gambas.
> >
> > First I have:
> >
> > DIM farmid AS NEW Integer[100000]
> > DIM farmx AS NEW Integer[100000]
> > DIM farmy AS NEW Integer[100000]
> > DIM farmwo AS NEW Integer[100000]
> > DIM farmcl AS NEW Integer[100000]
> > DIM farmir AS NEW Integer[100000]
> > DIM farmwh AS NEW Integer[100000]
> > DIM farmmx AS NEW Integer[100000]
> > DIM farmdd AS NEW Integer[100000]
> > DIM farmmm AS NEW Integer[100000]
> > DIM farmyyyy AS NEW Integer[100000]
> > DIM farmhh AS NEW Integer[100000]
> > DIM farmlcav AS NEW Integer[100000]
> >
>
> A few megabytes used there. It reminds me my Amstrad CPC464 when I had 48K
> memory free... :-)
>
> > That's fine, then in a file called ff.dat I have the following:
> >
> > 1
> > 142820 149 661 16 14 14 12 0 6 2009 0
> >
> > My problem is, this code is causing a break:
> >
> > ff = OPEN "~/ff.dat" FOR READ
> > INPUT #ff, farmers
> > PRINT farmers
> > FOR a = 1 TO farmers
> > INPUT #ff, farmid[a - 1], farmx[a - 1], farmy[a - 1], farmwo[a - 1],
> > farmcl[a - 1], farmir[a - 1], farmwh[a - 1], farmdd[a - 1], farmmm[a -
> > 1], farmyyyy[a - 1], farmhh[a - 1]
> > PRINT farmid[a - 1], farmx[a - 1], farmy[a - 1], farmwo[a - 1],
> > farmcl[a - 1], farmir[a - 1], farmwh[a - 1], farmdd[a - 1], farmmm[a -
> > 1], farmyyyy[a - 1], farmhh[a - 1]
> > farmmx[a - 1] = Max(Max(farmwo[a - 1], farmcl[a - 1]), Max(farmcl[a
> > - 1], farmir[a - 1]))
> > PRINT farmmx[a - 1]
> > NEXT
> > CLOSE #ff
> >
> > It's telling me that I am trying to put a string into an integer on the
> > 5th line. Which makes no sence because the file contains no strings,
> > just integers. I am at a loss to work this out.
> >
> > Beren
> >
>
> Please provide your project source, so that I can see what is wrong exactly.
>
> Regards,
>
-------------- next part --------------
' Gambas module file
PUBLIC SUB Main()
DIM world AS String 'world string
DIM mainx AS Integer 'main village x coord
DIM mainy AS Integer 'main village y coord
DIM timelag AS Integer 'timelag between server and player
DIM wci AS NEW Integer[30] 'wood clay iron data
DIM whc AS NEW Integer[30] 'warehouse capacity data
DIM df AS File 'df.dat
DIM vf AS File 'vf.dat
DIM ff AS File 'ff.dat
DIM villages AS Integer 'village count
DIM vllid AS NEW Integer[1000] 'village id
DIM vllx AS NEW Integer[1000] 'village x
DIM vlly AS NEW Integer[1000] 'village y
DIM m2v AS NEW Float[1000] 'main to village dist
DIM vllurl AS NEW String[1000] 'village url
DIM farmers AS Integer
DIM farmid AS NEW Integer[10000]
DIM farmx AS NEW Integer[10000]
DIM farmy AS NEW Integer[10000]
DIM farmwo AS NEW Integer[10000]
DIM farmcl AS NEW Integer[10000]
DIM farmir AS NEW Integer[10000]
DIM farmwh AS NEW Integer[10000]
DIM farmmx AS NEW Integer[10000]
DIM farmdd AS NEW Integer[10000]
DIM farmmm AS NEW Integer[10000]
DIM farmyyyy AS NEW Integer[10000]
DIM farmhh AS NEW Integer[10000]
DIM farmlcav AS NEW Integer[10000]
DIM farmeco AS NEW Float[10000]
DIM farmdist AS NEW Float[10000]
DIM farmurl AS NEW String[10000]
DIM curtime AS Date
' random varibles
DIM a AS Integer
df = OPEN "~/df.dat" FOR READ
' df.dat file read
INPUT #df, world, mainx, mainy, timelag
PRINT world, mainx, mainy, timelag
FOR a = 1 TO 30
INPUT #df, wci[a - 1]
PRINT wci[a - 1]
NEXT
FOR a = 1 TO 30
INPUT #df, whc[a - 1]
PRINT whc[a - 1]
NEXT
CLOSE #df
vf = OPEN "~/vf.dat" FOR READ
'vf.dat file read
INPUT #vf, villages
PRINT villages
FOR a = 1 TO villages
INPUT #vf, vllid[a - 1], vllx[a - 1], vlly[a - 1]
PRINT vllid[a - 1], vllx[a - 1], vlly[a - 1]
m2v[a - 1] = Sqr((mainx - vllx[a - 1]) ^ 2 + (mainy - vlly[a - 1]) ^ 2)
PRINT m2v[a - 1]
vllurl[a - 1] = "http://" & world & "/game.php?village=" & Str$(vllid[a - 1]) & "&screen=place&mode=command&target="
PRINT vllurl[a - 1]
NEXT
CLOSE #vf
ff = OPEN "~/ff.dat" FOR READ
INPUT #ff, farmers
PRINT farmers
FOR a = 1 TO farmers
INPUT #ff, farmid[a - 1], farmx[a - 1], farmy[a - 1], farmwo[a - 1], farmcl[a - 1], farmir[a - 1], farmwh[a - 1], farmdd[a - 1], farmmm[a - 1], farmyyyy[a - 1], farmhh[a - 1]
PRINT farmid[a - 1], farmx[a - 1], farmy[a - 1], farmwo[a - 1], farmcl[a - 1], farmir[a - 1], farmwh[a - 1], farmdd[a - 1], farmmm[a - 1], farmyyyy[a - 1], farmhh[a - 1]
farmmx[a - 1] = Max(Max(farmwo[a - 1], farmcl[a - 1]), Max(farmcl[a - 1], farmir[a - 1]))
PRINT farmmx[a - 1]
NEXT
CLOSE #ff
END
More information about the User
mailing list