Page 1 of 1
Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 2:23 pm
by agraham147
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
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 2:45 pm
by Klaus
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
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 4:18 pm
by agraham147
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.
Thanks, Aaron
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 4:36 pm
by Klaus
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.
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 5:28 pm
by agraham147
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.
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 5:31 pm
by dunbarx
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
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 5:32 pm
by Klaus
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?
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 5:53 pm
by agraham147
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?
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 6:03 pm
by Klaus
agraham147 wrote: ↑Mon Jul 20, 2020 5:53 pm
As for the dataSet question, what does that mean?
Replace
dataset with
fContents!

Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 6:04 pm
by agraham147
Also another thing to note is that the rogue empty bottom line doesn't hilite when you click it even though it's empty.
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 6:09 pm
by agraham147
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?
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 6:12 pm
by Klaus
No bug in LC, please post your namely repeat code!
Re: Data Grid keeps creating empty last line
Posted: Mon Jul 20, 2020 6:22 pm
by agraham147
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