data inputs from .Dat file

Collaborate on tools, libraries, and applications beyond the IDE

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
Shikha kumari
Posts: 19
Joined: Fri Feb 19, 2016 7:48 am

data inputs from .Dat file

Post by Shikha kumari » Wed Feb 24, 2016 6:43 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: data inputs from .Dat file

Post by Simon » Wed Feb 24, 2016 7:52 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Shikha kumari
Posts: 19
Joined: Fri Feb 19, 2016 7:48 am

Re: data inputs from .Dat file

Post by Shikha kumari » Wed Feb 24, 2016 10:15 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: data inputs from .Dat file

Post by Simon » Wed Feb 24, 2016 10:27 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Shikha kumari
Posts: 19
Joined: Fri Feb 19, 2016 7:48 am

Re: data inputs from .Dat file

Post by Shikha kumari » Thu Feb 25, 2016 12:33 pm

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.... :(

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: data inputs from .Dat file

Post by Simon » Thu Feb 25, 2016 9:16 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Shikha kumari
Posts: 19
Joined: Fri Feb 19, 2016 7:48 am

Re: data inputs from .Dat file

Post by Shikha kumari » Fri Feb 26, 2016 7:25 am

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 :?:

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: data inputs from .Dat file

Post by Simon » Fri Feb 26, 2016 7:36 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Shikha kumari
Posts: 19
Joined: Fri Feb 19, 2016 7:48 am

Re: data inputs from .Dat file

Post by Shikha kumari » Fri Feb 26, 2016 8:40 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: data inputs from .Dat file

Post by Simon » Fri Feb 26, 2016 10:10 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Shikha kumari
Posts: 19
Joined: Fri Feb 19, 2016 7:48 am

Re: data inputs from .Dat file

Post by Shikha kumari » Fri Feb 26, 2016 10:17 am

Thanks Simon.

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

Shikha

Post Reply

Return to “Community Projects”