datagrid

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
robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

datagrid

Post by robm80 » Tue May 13, 2014 5:11 pm

I can't get enough of Licecode, unless a wooden head.
What's now wrong in this button (copied from the tutorial)

on mouseUp
## Create tab delimited data.
##Note that first line has name of columns.
## Providing names tells Data Grid how to map
## data to appropriate columns.
put "naam" & tab & "adres" & "pc plaats"& cr & \
"ALBADA VAN, A." & tab & "Henricus Muntinghlaan 51" & "9751 PV,HAREN" &cr & \
"ALBERTS, E.J." & tab & "Westerveen 39" &",9745 HT,HAREN" &cr & \
"ALBERTS, J." & tab &"Westerveen 39" &"9751 HV,HAREN" &cr & \
"ALEKSANDER," & tab &"Woortsmandijk 1" &"9608 PK,WESTERBROEK"& cr & \
"ANDERZORG," & tab & "Postbus 1177" &"7500 BD,ENSCHEDE" &cr & \
"BEREGENING, DE BOER" & tab & "Scheiding 12" & tab &"9231 ANSurhuisterveen" into field "adres"
## Let Data Grid know that first line has column names
##put true into firstLineContainsColumnNames
##set the dgText [ firstLineContainsColumnNames ] of group "adres" to theText
end mouseUp

Why is "into the text not accepted? The field is named "adres"
What to do with this:
## Let Data Grid know that first line has column names
put true into firstLineContainsColumnNames
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid" to theText
Where do I find "firstLineContainsColumnNames"
Did "datagrid to be changed for "adres"?

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

Re: datagrid

Post by Klaus » Tue May 13, 2014 5:24 pm

Dag Rob,

1. you only create 2 columns in your script!
...
put "naam" & tab & "adres" & "pc plaats"
## Missing TAB after "adres"!
...
Is that what you want?

Or do you mean:
..
put "naam" & tab & "adres" & TAB & "pc plaats"
...
In that case you need to add some TABs to your script.

2. The extra parameter:
set the dgText [ firstLineContainsColumnNames ] ...
is only neccessary, if the itemdelimited data are NOT in the order as the columns in your datagrid!
That way it is made sure that the data will get put into the correct columns.

So if the columns in your datagfrid are:
1. naam
2. adres
3 pc plaats
You do not need that parameter, simple omit it:
...
set the dgtext of grp XYZ to THEDATA
...
and also leave out your first line!
...
## put "naam" & TAB & "adres"...
...

3. You set the DGTEXT of your datagrid group, whatever its name is.


Best

Klaus

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: datagrid

Post by robm80 » Tue May 13, 2014 8:07 pm

Hi Klaus,
I have send a wrong script. See the actual scipt here, where that line seems to be correct.

on mouseUp
put "naam" & tab & "adres" &tab& "pcplaats"& cr & \
"ALBADA VAN, A." & tab & "Henricus Muntinghlaan 51" & "9751 PV,HAREN" &cr & \
"ALBERTS, E.J." & tab & "Westerveen 39" &",9745 HT,HAREN" &cr & \
"ALBERTS, J." & tab &"Westerveen 39" &"9751 HV,HAREN" &cr & \
"ALEKSANDER," & tab &"Woortsmandijk 1" &"9608 PK,WESTERBROEK"& cr & \
"ANDERZORG," & tab & "Postbus 1177" &"7500 BD,ENSCHEDE" &cr & \
"AULT, L." & tab & "Gran Sol,0317 0" &"CALPE,Spanje" &cr & \
"BAKKER-KRAGTEN, H." & tab &"Benschopperweg 386" &"IJsselstein" &cr & \
"BARKMEIJER, H." & tab&"Hugo de Vriesweg 12" &"Haren" &cr & \
"BEKKERING-BROUWER, A." & tab &"v.Ketwich Verschuurlaan 25" &"Groningen" &cr & \
"BELASTINGDIENST NOORD," & tab &"Pb 418" &"Groningen" &cr & \
"BELASTINGDIENST, centrale administratie" & tab &"centrale administratie" &"Groningen" &cr & \
"BEREGENING, DE BOER" & tab & "Scheiding 12" & tab &"9231 AN Surhuisterveen" into field "DataGrid" --> compilation error at line 14 (Chunk: can't create a variable with that name (explicitVariables?)) near "table", char 93
end mouseUp

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: datagrid

Post by robm80 » Tue May 13, 2014 8:13 pm

Again I have send a wrong script; here the real actual one:

on mouseUp
put "naam" & tab & "adres" &tab& "pcplaats"& cr & \
"ALBADA VAN, A." & tab & "Henricus Muntinghlaan 51" & "9751 PV,HAREN" &cr & \
"ALBERTS, E.J." & tab & "Westerveen 39" &",9745 HT,HAREN" &cr & \
"ALBERTS, J." & tab &"Westerveen 39" &"9751 HV,HAREN" &cr & \
"ALEKSANDER," & tab &"Woortsmandijk 1" &"9608 PK,WESTERBROEK"& cr & \
"ANDERZORG," & tab & "Postbus 1177" &"7500 BD,ENSCHEDE" &cr & \
"AULT, L." & tab & "Gran Sol,0317 0" &"CALPE,Spanje" &cr & \
"BAKKER-KRAGTEN, H." & tab &"Benschopperweg 386" &"IJselstein" &cr & \
"BARKMEIJER, H." & tab&"Hugo de Vriesweg 12" &"Haren" &cr & \
"BEKKERING-BROUWER, A." & tab &"v.Ketwich Verschuurlaan 25" &"Groningen" &cr & \
"BELASTINGDIENST NOORD," & tab &"Pb 418" &"Groningen" &cr & \
"BELASTINGDIENST, centrale administratie" & tab &"centrale administratie" &"Groningen" &cr & \
"BEREGENING, DE BOER" & tab & "Scheiding 12" & tab &"9231 AN Surhuisterveen" into field "adres"
end mouseUp


execution error at line 14 (Chunk: no such object) near "adres", char 93: --> (the datagridfield is named "adres")

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

Re: datagrid

Post by Klaus » Tue May 13, 2014 8:56 pm

:D

1. You need to add TABs to your data if your have THREE columns in your datagrid!

Code: Select all

on mouseUp
  put "naam" & tab & "adres" &tab& "pcplaats"& cr & \
  "ALBADA VAN, A." & tab & "Henricus Muntinghlaan 51" & TAB & "9751 PV,HAREN" &cr & \
  ###etc...
2. You should put the data into a variable first...

Code: Select all

on mouseUp
  put "naam" & tab & "adres" &tab& "pcplaats"& cr & \
  "ALBADA VAN, A." & tab & "Henricus Muntinghlaan 51" & TAB & "9751 PV,HAREN" &cr & \
  ##...
  "BEREGENING, DE BOER" & tab & "Scheiding 12" & TAB &"9231 AN Surhuisterveen" into MyData
3. The error tells you that you do not have a FIELD named "adres"! 8)
So set the dgtext of your datagrid, which is a GROUP!, to that variable...

Code: Select all

...
  set the dgtext of grp "adres" to MyData
end mouseUp
Best

Klaus

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: datagrid

Post by robm80 » Wed May 14, 2014 7:50 am

Klaus: 2. You should put the data into a variable first...
I left the datagrid behind me and changed for a textfield'
What's wrong with this script:

on mouseUp
put "Naam"&","&& fld "adres"&","&&fld "pcplaats" into tLine
if fld "DB1" of cd "DB" is not empty then
put cr&tLine after fld "DB1" of cd "DB"
else
put tLine into fld "DB1" of cd "DB"
end if
end mouseUp
compilation error at line 2 (Chunk: can't create a variable with that name (explicitVariables?)) near "tLine", char 58
I have set the explicitVariables to true, but don't understand its relation with tLine

THANKS

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: datagrid

Post by bn » Wed May 14, 2014 9:04 am

Hi Rob,

if you set explicit variables to true you have to declare variables explicitely (hence the name) before you use them.

This means that if you want to use a variable tLine you first before you use it in your script have to

Code: Select all

on mouseUp
local tLine  -- here you declare the variable tLine
put "Naam"&","&& fld "adres"&","&&fld "pcplaats" into tLine
then it works. If you turn explicit variables off your original would work.


from the User Guide
5.10Tips for Writing Good Code
Explicit Variables
If you're working on a larger code base you may want to turn on the Variable Checking option in the Script menu of the Code Editor. This makes LiveCode require that you declare all variables (even script locals) before you can compile your script. It also requires you to place all literal strings in quotes. This method of coding can help you to quickly track down errors as you go by making you think a little about what variables you are going to use at an early stage, and pointing out spelling mistakes.
What's most important is that you develop your own consistent style and then stick to it. Once you have been applying some of these techniques for a short time, they will become second nature.
For a more in-depth look at this subject, we recommend Fourth World's Scripting Style Guide at:
http://www.fourthworld.com/embassy/arti ... style.html
You might also want to have a look at
5.5 Variables
in the User Guide

Kind regards
Bernd

Post Reply