Data Grid keeps creating empty last line

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
agraham147
Posts: 40
Joined: Thu Apr 19, 2018 6:18 am

Data Grid keeps creating empty last line

Post by agraham147 » Mon Jul 20, 2020 2:23 pm

Hi there,

I have a data grid which displays data from a text file, but it keeps creating a new empty line at the bottom. My data grid shows 14 lines at a time and so there is an auto scroll bar when more than 14 entries, there is currently 127 entries in my data grid and when I scroll down to the bottom there is a 128th empty line. How do I delete this line or stop the data grid from doing this as it's always doing this no matter how many entries?

Thanks,
Aaron

Klaus
Posts: 12008
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid keeps creating empty last line

Post by Klaus » Mon Jul 20, 2020 2:45 pm

Hi Aron,

sounds like there is a trailing CR in the text file?
That will cause an empty line in the datagrid.

How do you fill the datagrid? Do you set the DGTEXT to that text file
or are you creating an ARRAY first and then set the DGDATA of your datagrid?
If the first, you could :

Code: Select all

...
put url("file:" & "path to your text file here") into tTextFromFile

## Get rid of empty lines
filter tTextFromFile without empty
set the dgtext of grp "datagrid" to tTextFromFile
...
If that does not help, please post your script.


Best

Klaus

agraham147
Posts: 40
Joined: Thu Apr 19, 2018 6:18 am

Re: Data Grid keeps creating empty last line

Post by agraham147 » Mon Jul 20, 2020 4:18 pm

Hi Klaus,

I'm sorry to say that I tried that and that hasn't worked. This is my code:

Code: Select all

#FILLS THE 'fContents' VARIABLE WITH DATA
   put 0 into lNumber
   repeat mNumber times
      add 1 to lNumber
      put line lNumber of url ("file:" & mFilePath) into matchNumber
      add 1 to lNumber
      put line lNumber of url ("file:" & mFilePath) into roundName
      add 1 to lNumber
      put line lNumber of url ("file:" & mFilePath) into playerOne
      add 1 to lNumber
      put line lNumber of url ("file:" & mFilePath) into playerTwo
      add 1 to lNumber
      put line lNumber of url ("file:" & mFilePath) & "-" into matchResult
      add 1 to lNumber
      put line lNumber of url ("file:" & mFilePath) after matchResult
      if matchResult is "-" then
         put empty into matchResult
      end if
      if fContents is empty then
         put matchNumber & tab & roundName & tab & playerOne & tab & playerTwo & tab & matchResult into fContents
      else
         put return & matchNumber & tab & roundName & tab & playerOne & tab & playerTwo & tab & matchResult after fContents
      end if
   end repeat
   
   put "matchNum" & tab & "round" & tab & "player1" & tab & "player2" & tab & "result" & return & fContents into theText
   put true into firstLineContainsColumnNames
   set the dgText[firstLineContainsColumnNames] of group "matchList" to theText
Basically I have a repeat loop which takes seperate lines from the text file so that it's in the correct order that I want. All of that is working fine, the only thing is that it keeps creating a new empty entry at the bottom but I can't see a misplaced return command.
Image

Thanks, Aaron
Attachments
LC.png

Klaus
Posts: 12008
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid keeps creating empty last line

Post by Klaus » Mon Jul 20, 2020 4:36 pm

Hm, nothing to see in your script(s)!?
Try this one:

Code: Select all

  ...
   ## You are reading in the file X times, that is overkill and MUCH slower that using a variable!
   ## Put the content into a variable ONCE and continue with that variable!
   
   put ("file:" & mFilePath) into tFileContent
   #FILLS THE 'fContents' VARIABLE WITH DATA
   put 0 into lNumber
   repeat mNumber times
      add 1 to lNumber
      put line lNumber of tFileContent into matchNumber
      add 1 to lNumber
      put line lNumber of tFileContent into roundName
      add 1 to lNumber
      put line lNumber of tFileContent into playerOne
      add 1 to lNumber
      put line lNumber of tFileContent into playerTwo
      add 1 to lNumber
      put line lNumber of tFileContent & "-" into matchResult
      add 1 to lNumber
      put line lNumber of tFileContent after matchResult
      if matchResult is "-" then
         put empty into matchResult
      end if
      
      ## No need for an IF THEN lcause here
      put matchNumber & tab & roundName & tab & playerOne & tab & playerTwo & tab & matchResult & CR AFTER  fContents
      
   end repeat
   
   ## Now delete last CR of fContents
   delete char -1 of fContent
   
   put "matchNum" & tab & "round" & tab & "player1" & tab & "player2" & tab & "result" & CR & fContents into theText
   ##put true into firstLineContainsColumnNames
   set the dgText[TRUE] of group "matchList" to theText
   ...
And please check if in -> repeat mNumber times
mNumber really holds the correct number of lines and not one more!
Sounds like the empty lines comes from this.

agraham147
Posts: 40
Joined: Thu Apr 19, 2018 6:18 am

Re: Data Grid keeps creating empty last line

Post by agraham147 » Mon Jul 20, 2020 5:28 pm

I've copied the code and no difference, it's still adding an empty line, even when I go into the property inspector there isn't an empty line in there.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7019
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Data Grid keeps creating empty last line

Post by dunbarx » Mon Jul 20, 2020 5:31 pm

Is it possible that the last TWO chars of the dataSet are return?

Code: Select all

repeat until the last char of yourData <> CR
delete the last char of yourData
...
Craig

Klaus
Posts: 12008
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid keeps creating empty last line

Post by Klaus » Mon Jul 20, 2020 5:32 pm

And please check if in -> repeat mNumber times
mNumber really holds the correct number of lines and not one more!
Sounds like the empty lines comes from this.
How do you compute -> mNumber?

agraham147
Posts: 40
Joined: Thu Apr 19, 2018 6:18 am

Re: Data Grid keeps creating empty last line

Post by agraham147 » Mon Jul 20, 2020 5:53 pm

mNumber variable is worked out by a simple repeat loop that counts the number of lines in the text file, and then divides the total by 6 as every six lines in the file is an entry in the data grid e.g 6 lines = 1 entry, 60 lines = 10 entries. All that is working fine as well.

As for the dataSet question, what does that mean?

Klaus
Posts: 12008
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid keeps creating empty last line

Post by Klaus » Mon Jul 20, 2020 6:03 pm

agraham147 wrote:
Mon Jul 20, 2020 5:53 pm
As for the dataSet question, what does that mean?
Replace dataset with fContents! 8)

agraham147
Posts: 40
Joined: Thu Apr 19, 2018 6:18 am

Re: Data Grid keeps creating empty last line

Post by agraham147 » Mon Jul 20, 2020 6:04 pm

Also another thing to note is that the rogue empty bottom line doesn't hilite when you click it even though it's empty.

agraham147
Posts: 40
Joined: Thu Apr 19, 2018 6:18 am

Re: Data Grid keeps creating empty last line

Post by agraham147 » Mon Jul 20, 2020 6:09 pm

I've just implemented that repeat loop into my code and it's still not making a difference, could this be a bug in LiveCode?

Klaus
Posts: 12008
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid keeps creating empty last line

Post by Klaus » Mon Jul 20, 2020 6:12 pm

No bug in LC, please post your namely repeat code!

agraham147
Posts: 40
Joined: Thu Apr 19, 2018 6:18 am

Re: Data Grid keeps creating empty last line

Post by agraham147 » Mon Jul 20, 2020 6:22 pm

It's ok guys, I've just created a new dataGrid and copied the specs of the first one, and this new one is working properly. Thanks for everyone's help.

Thanks,
Aaron

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”