Page 1 of 1

data inputs from .Dat file

Posted: Wed Feb 24, 2016 6:43 am
by Shikha kumari
I am working on a project that needs data to be entered by the outsource like .Dat file. i am unable to find anything suitable for this..
plss help me out with some hint in the coding.

Re: data inputs from .Dat file

Posted: Wed Feb 24, 2016 7:52 am
by Simon
Hi Shikha,
Take a look at this;
http://lessons.livecode.com/m/4071/l/96 ... -text-file
Now that's a text file, a binary file is similar.

Simon

Re: data inputs from .Dat file

Posted: Wed Feb 24, 2016 10:15 am
by Shikha kumari
I am trying to make something that will work as real time. when i will open it, it will update the data automatically and provide me with the recent data. hence for this file m starting with the fetching of information from dat file or a text file and deal with that. the information shared with me above is all about importing a text file but i want to import the data in a file and updating the last data with respect to imported data.

Re: data inputs from .Dat file

Posted: Wed Feb 24, 2016 10:27 am
by Simon
but i want to import the data in a file and updating the last data with respect to imported data.
While there is an "answer file" do you see how later on it has the "put URL..."
With the "put URL" if you already know the file location then you don't need the "answer file".
So you do the "put URL..." into a variable then update the variable and use "put myVar into URL..." back into the text file, similar format as when you load the file.

Simon

Re: data inputs from .Dat file

Posted: Thu Feb 25, 2016 12:33 pm
by Shikha kumari
Thank you for your advice.
I have a text file named "abc.txt" in my Local disk, i tried "read from....", "get URL..." , "Put URL..." command to get data from my text file and put it into a field.
i guess as i am new to liveCode i couldn't be able to use these command rightly into the code form.

Will you guide me in proper form to use these commands so that it will work. I tried but nothing happened, no data is fetched from text file and displayed in the field.... :(

Re: data inputs from .Dat file

Posted: Thu Feb 25, 2016 9:16 pm
by Simon
Hi Shikha,
From the lesson;

Code: Select all

    on mouseUp
        answer file "A text file"
        if it <> "" then
            put it into theFilePath
            put URL ("file:" & theFilePath) into field "text"
        else
            --no file was selected, or cancel was pressed
            beep
        end if
    end mouseUp
One of the things that often happens is people get the path to the file incorrect. That "answer file" ensures the path is right.
I suggest you use this to method just to get the path, it will end up in the "it" variable which then gets put into theFilePath variable. Throw a breakpoint in and copy theFilePath. Put copied text into

Code: Select all

put URL ("file:c://the copied text/whatever/mytext.txt") into field "text"
Now you can delete the answer file stuff and you should be good to go.

Simon

Re: data inputs from .Dat file

Posted: Fri Feb 26, 2016 7:25 am
by Shikha kumari
Thank you Simon. I am really grateful as i found the way as per u told.

Now i tried some experiments over the code u provided. I added some more codes and try to read a particular data from a text file, but i am unable to perform accurately i willing to do. firstly i tried to use the "read from..." command and read my text from start to the point i mentioned, i succeeded. But when i tried using it like i want to read it from after the space i am unable to do so.

Code: Select all

read from file theFilePath at " "

it is returning me the file path but not with the text.
how can i read my text in the field from a particular point till a point :?:

Re: data inputs from .Dat file

Posted: Fri Feb 26, 2016 7:36 am
by Simon
Hi Shikha,
If you could post the text you are trying to read, we might be able to help you find a better way.
Maybe just a portion of it, but tell us which part you want.

Simon

Re: data inputs from .Dat file

Posted: Fri Feb 26, 2016 8:40 am
by Shikha kumari
Calls | Agents | rest time | Talk time
25 | 5 | 0:15:25 | 0:59:45
I need to read the word till the "|" and put it in the specific field.
For example: i have four fields namely- field 1, field 2, field 3 and field 4 now,
in field 1 i want the data "Calls" to be printed,
in field 2 i want "agents" to be printed .
in field 3 i want "rest time".....and so on
through this it will be like whenever the text file is updated the field will be updated accordingly.

i guess it be done with the "read from..." command but unable to find the proper way.

Re: data inputs from .Dat file

Posted: Fri Feb 26, 2016 10:10 am
by Simon
Hi Shikha,
After you have imported the text file via "put URL..."
Use

Code: Select all

set itemDelimiter to "|"
Then each of the items can be selected by

Code: Select all

put item 1 of myVar into tItem1--... etc.
I rarely use "read from"
If there are multiple lines, something I've never tried

Code: Select all

put item 1 of line 5 of myVar into tItem15
But I think it would work.

The important thing here is the "set itemDelimiter"
And I think the world likes tab over pipe (|) so if you can change that, cool.

Simon

Re: data inputs from .Dat file

Posted: Fri Feb 26, 2016 10:17 am
by Shikha kumari
Thanks Simon.

I myself now think it's the best way out. It will definitely gonna work accordingly as per i required.

Shikha