Re: Liberty Basic
- Posted by Kasey <kaeyb at GEOCITIES.COM> Apr 26, 1998
- 690 views
David Mosley wrote: > > Hi > The problem I think is that in basic it is easy to get an array set up in > euphoria it is not.What I want to do is this > my data file looks like this > How old are you? > 37 > What time of day is it? > 2pm > In basic I would do this like > open "l1.dat" for input as #1 > for t=1 to 2 > input #1,a$ 'read in data > a1$(t)=a$ ' put in to array > input #1,q$ > q1$(t)=q$ > next t > close #1 > Hope this helps > the url for LB is down below,LB is a Windows programing lang. that is really > easy to use. > http://world.std.com/~carlg/basic.html > In Christ > David Mosley > mosley01 at geocities.com > or > david08 at juno.com if you can change how the file is writen (so that it starts with the number of entries in it) you could do somthing like this (no real error checking in this, nor have I tried it, but it should be close) ------------begin code snipet--------- include dim.e --- o.k. this is my include, but it's what I'd use -- because for me it's the easiest way. include get.e --- net this to use get() function read_data() integer fn,size sequence instr, data fn = open ("data.dat","r")--- replace data.dat with file your reading if fn = -1 then printf(1,"can't open data.dat","") abort(99) end if size = get(fn) size = size[2] data = dim({size,2}) --- create a [size][2] array for t = 1 to size do instr = get(fn) data[t][1] = instr[2] --- read question #t instr = get(fn) data[t][2] = instr [2] --- and then the answer end for --- notice the lack of error checking in the above loop --- the real prog would neet to watch for EOF return data end function ---------end code sample------------ you'd have to change your data file to from: How old are you? 37 What time of day is it? 2pm to : {2} {How old are you?} {37} {What time of day is it?} {2pm} I'm not positive you'd need the braces ( the { and } symbols) (do I need them? anyone ??) but that's how my data files are and they work( I used a euphoria program and the print() procedure to generate them) and they do need to be on seperate line(missed that once! ouch). The reason for {2} at the top is so if the data file is changed as long as it starts with the total number of question/answer pairs (pairs not q + a!) the function can read it correctly. the reason I used my dim.e and the dim function is so I didn't have to worry about getting my appends and &'s right, plus I get some independance between how I read the file and how the data is stored in the vaiable (plus dim.eis less than 20 lines against my 300 total (I WILL register as soon as I have the cash to spare, I'm still catching up on bills from this winter:( ) ) Hope this helps with your problem. Kasey