unknown bug in my lineoffset code

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

unknown bug in my lineoffset code

Post by ittarter » Tue Mar 29, 2016 4:22 pm

Hi guys,

I can't figure out where I'm going wrong here.

the first line of fld "chapter info" is
[chapterID] 01
(these items are tab delimited)

So when I put this line in the Message Box,

Code: Select all

put lineoffset(tab & "01",fld "chapter info")
I get a result of 1, as I should.

However, my ACTUAL code doesn't work:

Code: Select all

put the selectedtext of fld "downloadlist" into tChap
   put lineoffset(tab & tChap,fld "Chapter info") into tLine
yields 0. tChap is still 01 (I can see this in the variables tracker of the script editor). I can also search for "[chapterID]" & tab & tChap, with the same result, 0.

What is going on?? I mean, I can always do a repeat for each line, that searches for an item 2 of tLine equal to tChap, but that's just so messy...

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: unknown bug in my lineoffset code

Post by FourthWorld » Tue Mar 29, 2016 4:48 pm

You might double-check the hilitedText of the list field to make sure it contains no extra tabs, spaces, or other white characters which could account for the seeming disparity.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: unknown bug in my lineoffset code

Post by ittarter » Wed Mar 30, 2016 6:51 am

Nope, not that. Thanks for the help though. I've given up and switched over to a repeat-based search of the field.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: unknown bug in my lineoffset code

Post by [-hh] » Wed Mar 30, 2016 4:07 pm

tChap may start with a tab? (The variable tracker updates slowly ...)

You could try

Code: Select all

put the selectedtext of fld "downloadlist" into tChap
replace tab with empty in tChap #<-----
put lineoffset(tab & tChap,fld "Chapter info") into tLine
[Also, if you don't really need the line number but eventually the content of that line then you could also think about using "filter".]
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: unknown bug in my lineoffset code

Post by FourthWorld » Wed Mar 30, 2016 5:18 pm

ittarter wrote:Nope, not that. Thanks for the help though. I've given up and switched over to a repeat-based search of the field.
If the repeat loop succeeds with the same data that lineoffset failed with, it would be interesting to see the loop code to determine what was wrong with the lineoffset call.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: unknown bug in my lineoffset code

Post by jacque » Wed Mar 30, 2016 6:07 pm

When this happens to me I do something like this:

Code: Select all

put the selectedtext of fld "downloadlist" into tChap
answer (tChap=01)
set the clipboardData to tChap
Select the known first chapter (to get 01) and run the handler. If the comparison yields false, open a text editor and paste. Have the editor show invisible characters, and usually you can see what the problem is.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: unknown bug in my lineoffset code

Post by ittarter » Wed Mar 30, 2016 11:02 pm

FourthWorld wrote: If the repeat loop succeeds with the same data that lineoffset failed with, it would be interesting to see the loop code to determine what was wrong with the lineoffset call.
Well, here it is! (The field with chapters listed was changed to a combo box for aesthetic reasons.)

Code: Select all

put pItemName into tChap
repeat for each line tThis in fld "chapter info"
      add 1 to tCount
      if item 2 of tThis = tChap then
         put tCount into tLine
         exit repeat
      end if
   end repeat
Zero problems. So yeah, weird.

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: unknown bug in my lineoffset code

Post by ittarter » Wed Mar 30, 2016 11:07 pm

[-hh] wrote:[Also, if you don't really need the line number but eventually the content of that line then you could also think about using "filter".]
I need the line number. It's the first line of a block of data that is being called line by line. It's not sexy but it works. item 2 of line (tLine +1), item 2 of line (tLine +2), and so forth.

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: unknown bug in my lineoffset code

Post by ittarter » Wed Mar 30, 2016 11:09 pm

jacque wrote:

Code: Select all

put the selectedtext of fld "downloadlist" into tChap
answer (tChap=01)
set the clipboardData to tChap
Line 2 is a new concept to me. It's like an if statement and results in true if tChap = 1, false otherwise? Neato.

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

Re: unknown bug in my lineoffset code

Post by jacque » Wed Mar 30, 2016 11:43 pm

I should have put the number in quotes though to make it a literal string: answer (tChap="01")

Without the quotes, the engine will evaluate tChap as a number, which would match either "1" or "01" or "0001" and still evaluate to true. With the quotes, the string must match exactly. Also, technically, you don't need the parentheses but it makes reading the script easier for me. It would work the same if you wrote: answer tChap = "01"

Edit: do you have wholeMatches set to true? That would cause a lineoffset to fail.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply