14
« on: August 31, 2018, 04:06:00 pm »
thanks for all the help guys i'm kinda stuck here trying to incorporate that function bplus gave me into what I had started so i'll post my code and hopefully someone can lead me in the right direction I feel like an idiot for having to ask again at this point but have only been using qb64 for about a month now but I have a large data file when someone besides me and danny want to play I have to go into it manually and add them to the program
TYPE kstats
name AS STRING * 10
ktg AS LONG 'keiths total games
ktw AS LONG 'keiths total wins
kgd AS LONG 'keiths games against dan
kwd AS LONG 'keiths wins against dan
kab AS LONG 'keiths at bats
kh AS LONG 'keiths hits
ka AS DOUBLE 'keiths average
END TYPE
DIM SHARED keith AS kstats
recordlen% = LEN(keith)
keith.name = "Keith": keith.ktg = 0: keith.ktw = 0: keith.kgd = 0: keith.kwd = 0: keith.kab = 0: keith.kh = 0: keith.ka = 0
OPEN "kdata " FOR RANDOM AS #1
PUT #1, 1, keith
CLOSE #1
TYPE dstats
name AS STRING * 10
dtg AS LONG 'dans total games
dtw AS LONG 'dans total wins
dgk AS LONG 'dans games against keith
dwk AS LONG 'dans wins against keith
dab AS LONG 'dans at bats
dh AS LONG 'dans hits
da AS DOUBLE 'dans average
END TYPE
DIM SHARED danny AS dstats
recordlen% = LEN(danny)
danny.name = "Danny": danny.dtg = 0: danny.dtw = 0: danny.dgk = 0: danny.dwk = 0: danny.dab = 0: danny.dh = 0: danny.da = 0
OPEN "ddata " FOR RANDOM AS #2
PUT #2, 1, danny
CLOSE #2
'from here down my guesses on how to change what i started as 2 seperate random files into one big data file to be able to add names
'first i only need one type with all the same variables the exception being games against other players but just make a seperate file for that
'i'm kinda getting lost here if i use kdata as the type for each record and players for the big data file i'm thinking it would go something like
'open "players" for random as #1
'get #1,,kdata
'close #1
'then the two players enter their names
'input "Player 1 Enter your name ";player1$
'input "Player 2 Enter your name ";player2$
'kdata.name = player1$
'then i would have to call the recordpos function which i'm not sure how to do and check to see if player1 is already on file and what record number
'and when it gets back call it again to check player2
FUNCTION RecordPos (file$, search$) 'file$ = ddata search$ = danny.name
f = FREEFILE
OPEN file$ FOR INPUT AS #f 'file$ = ddata
FL = LOF(f)
dat$ = INPUT$(FL, f) '<<<<<<<<<<<<<<<<<<<<< this takes the whole file and loads it into one giant string =dat$
CLOSE f
recpos = INSTR(dat$, search$) '>>>>>>>>>>>>>>>>>>>>>> this seaches the giant string for Bob, if finds Bob returns the position in string
IF recpos THEN RecordPos = recpos \ recLEN + 1 ELSE RecordPos = 0 ' >>> this converts the find position in string to a record number for Random access of that record
END FUNCTION