How to read from a file every 3 lines until eof

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: How to read from a file every 3 lines until eof

Post by jacque » Wed Jun 10, 2015 4:42 pm

dunbarx wrote: The process runs 30% SLOWER if I do not empty the fields. I only did that for feedback. It actually takes a little time to empty them. I get about 315 ticks if I empty, and 400 if I do not
It would probably take about the same amount of time if you start the timer before the first two lines that empty the fields. Or did you try that?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: How to read from a file every 3 lines until eof

Post by alemrantareq » Thu Jun 11, 2015 6:20 am

Hi jacque, its really amazing; the process that took about 3 mins now just completed within 10 secs for taking the result into a variable. Special Thanks to you and Craig for the amazing trick. Btw, can you tell me is it possible to scroll 2 fields at the same time? I mean if I scroll field 1, it will auto scroll field 2 too. Thanks

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: How to read from a file every 3 lines until eof

Post by zaxos » Thu Jun 11, 2015 10:52 am

How bout showing a loading animation while livecode procceses the data? Even tho it dosent show the exact percentage of the progress, atleast the user knows that he has to wait.
You can find some here: http://preloaders.net/en/circular
As for the scrollBars i guess you could do something like that:
field 1 code:

Code: Select all

on scrollbardrag 
 set the thumbPosition of fld 1 to the thumbPosition of me
end scrollbardrag
field 2 code:

Code: Select all

on scrollbardrag 
 set the thumbPosition of fld 2 to the thumbPosition of me
end scrollbardrag
Knowledge is meant to be shared.

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to read from a file every 3 lines until eof

Post by Klaus » Thu Jun 11, 2015 12:13 pm

Hi zaxos,

Code: Select all

set the thumbPosition of fld 2...

Are you sure? :shock:


Best

Klaus

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: How to read from a file every 3 lines until eof

Post by alemrantareq » Thu Jun 11, 2015 12:58 pm

thanks zaxos; I've corrected your script to the working one

Code: Select all

on scrollbarDrag
   set the vScroll of fld "f2" to the vScroll of me
end scrollbarDrag

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to read from a file every 3 lines until eof

Post by Klaus » Thu Jun 11, 2015 1:09 pm

Code: Select all

on scrollbarDrag
   set the vScroll of fld "f2" to the vScroll of me
end scrollbarDrag
Yep, now THAT makes sense :D

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: How to read from a file every 3 lines until eof

Post by alemrantareq » Thu Jun 11, 2015 1:14 pm

Klaus wrote:

Code: Select all

on scrollbarDrag
   set the vScroll of fld "f2" to the vScroll of me
end scrollbarDrag
Yep, now THAT makes sense :D
:D :D :D

hi Klaus, I have a Menubar which has a background color (check my snapshot) although I've checked in its Property Inspector there's no background color set. Is it possible to remove that background color?
Attachments
Untitled.png
Untitled.png (717 Bytes) Viewed 7897 times

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to read from a file every 3 lines until eof

Post by Klaus » Thu Jun 11, 2015 1:49 pm

If you do not explicitely set a property, it gets inherited from the object higher in hierarchie like this:
button -> group -> card -> stack

So the best way in your case is to uncheck the OPAQUE property for your buttons! :D

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: How to read from a file every 3 lines until eof

Post by alemrantareq » Thu Jun 11, 2015 2:18 pm

I've edited the menu group and uncheck "Opaque" option for both buttons; but still it's showing the background :(

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to read from a file every 3 lines until eof

Post by Klaus » Thu Jun 11, 2015 2:29 pm

Then you see the color of the object(s) BEHIND your buttons! 8)

Set a backcolor for your buttons so they look like they have NO color set, know what I mean?

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: How to read from a file every 3 lines until eof

Post by alemrantareq » Thu Jun 11, 2015 2:52 pm

I've already tried that before; but it's not effective though. Then I've removed the menubar built by "Menu Builder"; and created a new pulldown menu which has no background color and perfect as I expected. The problem goes with the "Menubar Builder" menu. But Klaus, I'm always thankful for your tricky replies :D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: How to read from a file every 3 lines until eof

Post by jacque » Thu Jun 11, 2015 3:59 pm

Menu builder creates a transparent menu group. You can make it opaque and stretch it to fit the width of your stack, and then set its color to anything you want. Then I usually make all the menu buttons transparent.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: How to read from a file every 3 lines until eof

Post by jacque » Thu Jun 11, 2015 4:03 pm

[quote="alemrantareq"]Hi jacque, its really amazing; the process that took about 3 mins now just completed within 10 secs for taking the result into a variable. Special Thanks to you and Craig for the amazing trick./quote]

Quoting all literals, like object names, is another way to speed up scripts. The effects aren't as dramatic as using variables instead of fields, but in repeat loops the differences are noticeable. Always quote literals.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: How to read from a file every 3 lines until eof

Post by alemrantareq » Sun Jun 14, 2015 7:20 pm

hello, now I'm stuck again. I have 2 columns:

Col 1 (sample)
sjjwjas
dwaiask
dlawla
hylallu

Col 2 (sample)
31316
63676
97761
41731

I want to combine then together. So the expected return will be:
sjjwjas-31316
dwaiask-63676
dlawla-97761
hylallu-41731

Is that possible by repeat loop process? thanks...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: How to read from a file every 3 lines until eof

Post by dunbarx » Mon Jun 15, 2015 5:25 am

HI.

Code: Select all

repeat with y = 1 to the number of lines of fld "sample1"
put line y of fld "sample1" & "-" & line y of fld "sample2" into line y of temp
end repeat
put temp into fld "combinedData"
See any traps with this?

And you are working on the basics of LC while all this is going on, right?

Craig

Post Reply