Remove Carriage Returns

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

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 6:59 pm

Your last question asked was the DataGrid a form? I've answered it twice. It is a form.

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

Re: Remove Carriage Returns

Post by Klaus » Thu Mar 31, 2016 7:08 pm

Of course I meant my last unanswered (sic!) question. 8)

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 7:16 pm

OK, that is the SQL command. What about the LC command you are using the SQL in?

The one posted was it. The SQL and LC are all together.

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 7:19 pm

set the text of field "Description" of me to pDataArray["label 11"]

is used to populate the Description field in the Row Behavior. The event_description is the 11th item in the array.

Hope that helps some.

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

Re: Remove Carriage Returns

Post by Klaus » Thu Mar 31, 2016 7:39 pm

bbhank wrote:OK, that is the SQL command. What about the LC command you are using the SQL in?
The one posted was it. The SQL and LC are all together.
No, that was only the SQL part!
You are also using something like "revexecute..." or "revdatafromquery..." to finally execute the SQL command, right?
And THAT is the LC part that I mean.

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 7:47 pm

Yes. Here: put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData in the query part.
:?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Remove Carriage Returns

Post by jacque » Thu Mar 31, 2016 9:01 pm

You're doing to us what you say the dictionary does to you. :)

Klaus (and I) would like to know exactly where you were trying to adjust the text. Was it in the behavior script? Which handler? "FillInData"? (That's where I would have done it.)

Of course, the easiest solution is what you actually did. Updating the database source is faster and easier than manipulating the text as it comes into LC.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 9:36 pm

Please excuse delay. Had to run out. And thank you all.

I've been trying both in the query, as per stuff I found outside LiveCode, and from the Row Behavior - set the text of field "Description" of me to pDataArray["label 11"].

I only updated the database to see if that was the issue. If I change records in the database I risk the ire of customers who use the main program on the web. Users do things like using spaces and returns to make text look and feel like they want so they can print what they see. That makes this problem worse by adding more carriage returns and line feeds. The main program, a calendar, does not see any of this so they can format their Descriptions any way they see fit. The other is where many of the descriptions are pasted in, especially from Acrobat. You probably know what problems can arise from copying and pasting from that :wink: :D .

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Remove Carriage Returns

Post by jacque » Thu Mar 31, 2016 9:42 pm

Okay, good. Can we see your fillInData handler from the row behavior script? That's where the adjustment should go.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Remove Carriage Returns

Post by jacque » Thu Mar 31, 2016 9:44 pm

Oh wait, I've got enough info from your other response:

Code: Select all

put pDataArray["label 11"] into tData
replace cr with empty in tData
set the text of field "Description" of me to tData
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

AxWald
Posts: 367
Joined: Thu Mar 06, 2014 2:57 pm

Re: Remove Carriage Returns

Post by AxWald » Thu Mar 31, 2016 9:56 pm

Hi,

a few more hints about this:

Code: Select all

 Here: put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
is a potential culprit. It adds additional linefeeds (see Dictionary CR, which is synonym to Return).
When working with data containing such already you'll want to use other delimiters, for instance:

Code: Select all

 Here: put revDataFromQuery(numtochar(1), Numtochar(2), gConnectionID, tSQL) into tData
This way you'll get the delimiters not conflicting with your data. Now do:

Code: Select all

replace CRLF with return in tData
(see Dictionary CRLF)
You have nice, clear data now. Try:

Code: Select all

split tData by numtochar(1) and Numtochar(2)
this should give you an array to feed to a DataGrid.

For sure, you could always use:

Code: Select all

replace CRLF with empty in tData
replace return with empty in tData
replace numtochar(1) with tab in tData
replace numtochar(2) with return in tData
instead of the above paragraph.

Got the idea? Have fun!

PS: I see, Jacque was faster. Anyways, if I wrote this already, I can send it too :)
Livecode programming until the cat hits the fan ...

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Thu Mar 31, 2016 10:43 pm

Here ya go:

Code: Select all

on FillInData pDataArray
set the text of field "City" of me to pDataArray["label 1"]
   set the text of field "State" of me to pDataArray["label 2"]
   convert pDataArray["label 3"] to long date
   set the text of field "Begins" of me to pDataArray["label 3"]
   set the text of field "Title" of me to pDataArray["label 4"]
   set the text of field "Lane" of me to pDataArray["label 5"]
   set the text of field "Street" of me to pDataArray["label 6"]
   set the text of field "Link" of me to pDataArray["label 7"]
   get wordWrapped(field "Link",35)
   -- put wordWrapped(myText,the length of line 1 of me) after me
   put wordWrapped(it) into field "Link" of me
   set the text of field "Phone" of me to pDataArray["label 8"]
   set the text of field "Zipcode" of me to pDataArray["label 9"]
   set the text of field "Category" of me to pDataArray["label 10"]
   -- set the text of field "Description" of me to pDataArray["label 11"]
end FillInData

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

Re: Remove Carriage Returns

Post by Klaus » Fri Apr 01, 2016 10:43 am

AxWald wrote:

Code: Select all

 Here: put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
is a potential culprit. It adds additional linefeeds (see Dictionary CR, which is synonym to Return).
When working with data containing such already you'll want to use other delimiters, for instance:

Code: Select all

 Here: put revDataFromQuery(numtochar(1), Numtochar(2), gConnectionID, tSQL) into tData
This way you'll get the delimiters not conflicting with your data. Now do:

Code: Select all

replace CRLF with return in tData
(see Dictionary CRLF)
You have nice, clear data now. Try:

Code: Select all

split tData by numtochar(1) and Numtochar(2)
this should give you an array to feed to a DataGrid..
Yep, that is exactly the problem here!

bbhank, do you understand why this is causing your problem?
It is important to konw and understand how and why something works in any programming environment.

bbhank
Posts: 116
Joined: Thu Mar 17, 2016 6:04 pm

Re: Remove Carriage Returns

Post by bbhank » Fri Apr 01, 2016 11:11 am

I think so. IF I'm understanding you correctly, looks like we're taking the returns out of the whole query results, then splitting that up. It's the Description field only I'm asking about. Taking them out of tData wrecks everything. The problem only happens when the Description field is loaded.
replace CRLF with "---" in field "Description" seems to have no effect. I know they are there because i can take them out with Word and get a "normal" field, in that the data is totally contained in one field and row.

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

Re: Remove Carriage Returns

Post by Klaus » Fri Apr 01, 2016 1:22 pm

Hi bbhank,

Code: Select all

...
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
...
Please take alook at the first 2 parameters of this function -> TAB and CR
This way the data returned from the database will be delimited by TAB for
database fields belonging to one database record and all records delimited
by CR (RETURN).

This is great for ONE LINE content like any address database like in this example:
name1 TAB firstname1 TAB telephone1 CR
name2 TAB firstname2 TAB telephone2 CR
...
You get the picture!

But if the content of a database field already contains any CR it will completely
spoil your intention, as you have experienced.

So we need to take another RECORD delimiter for your query, some thong that is surely
NOT part of the text in the database fields.

That is why AxWald use numtochar(1) resp. numtochar(2).
These "characters" cannot be typed with the keyboard and so the contained CRs will not
destroy your layout.

Of course you will need to take this into account when converting your data to an array for
the datagrid.

Hope this is clearer now.


Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”