1. Liberty Basic

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

new topic     » topic index » view message » categorize

2. Re: Liberty Basic

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Liberty Basic

>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

Euphoria translation:


object junk

integer fn
sequence question, answer

question = {}
answer = {}

fn = open("l1.dat", "r")   -- Open as read only
for t = 1 to 2 do
    junk = gets(fn)        -- Read in data
    if sequence(junk) then -- Data ok?
        question = question & {junk[1..length(junk)-1]}   -- Put into
array
    end if
    junk = gets(fn)        -- Read in data
    if sequence(junk) then -- Data ok?
        answer = answer & {junk[1..length(junk)-1]}   -- Be sure to strip
\n
    end if
end for
close(fn)


Oh, and this snippit doens't reverse the q and a strings (It puts the
questions into question unlike the BASIC version which puts the question
into a$... ;)

It may look a little more complex, but that's due to checking for EOF and
such, but I didn't check to see if the file exists. I think that the
Euphoria version is easier to understand, too. Just have to be familiar
with it.

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu