Discussion:
Explain why I get carriage and line return
(too old to reply)
Claus Mygind
2008-11-26 13:05:17 UTC
Permalink
I use the code below to assemble a string of values. I separate each value
with the ; so my receiving app can quickly disect the values into an array.
My problem is this, the last value is always returned with the \n\r
attached. Now I can just strip it out like I do with the last ; (see last
line of code below). But I am intrested in knowing why it happens?

do while not q.rowset.endOfSet

responseText += trim( c['phasecode'].value )+";"

q.rowset.next()

enddo

responseText = subStr( responseText, 1, ( rat(";",
responseText)-1 ) )
Claus Mygind
2008-11-26 13:43:58 UTC
Permalink
This is getting to be a pain in the butt tried simply to remove the last 3
characters

responseText = substr(responseText,1, len(responseText)-3)

That only removed the ; and the last 2 digit value and left in the \r\n
Mervyn Bick
2008-11-26 13:59:50 UTC
Permalink
Post by Claus Mygind
This is getting to be a pain in the butt tried simply to remove the last 3
characters
responseText = substr(responseText,1, len(responseText)-3)
That only removed the ; and the last 2 digit value and left in the \r\n
The fact that it removed the ; and two digits from the last value proves
that there was no CRLF at the end of responseText. If there had been a
CRLF at the end it would have counted as two characters and together with
the ;, removing the last three characters would have left the last
phasecode intact. If there is still a CRLF at the end of the string after
you have truncated the last phasecode then it is not in the field in the
table. There must be some other code that you are not showing that is
adding it.

Your previous code, responseText =
subStr(responseText,1,(rat(";",responseText)-1)) is a better option anyway
for removing the final ;. This would remove the last ; and any CRLF if it
was there. If there was no CRLF (and there shouldn't be) then it will
only remove the last ;.


Mervyn.
Mervyn Bick
2008-11-26 14:53:29 UTC
Permalink
Nothing to hide here. Here is the entire app code. The app receives
two
parameters, the job # JOBID and a department # and employee belongs to
JDEPTID.
Two queries are conducted and strung together for a response separated by
the ~ sign. Within each string I separate the values with the ;
So as to not create an extra empty array element at the end the last ; is
stripped away. Now for those nasty little carriage and line returns.
.........
oCGI.fOut.puts("Content-type: text/html")
oCGI.fOut.puts('')
oCGI.fOut.puts(responseText)
I think we have the culprit. <g> I don't see where oCGI comes into being
or what it actually is but puts(), which is a synonym for writeln(), is a
method in the File class. When used to write data to a file, puts() adds
a CRLF by default although other terminators can be specified. Write()
only writes the actual string without adding anything so if you use
write() instead ie oCGI.fOut.write(responseText) it may solve your problem.

Mervyn.
Claus Mygind
2008-11-26 16:11:31 UTC
Permalink
Mervyn,

IT WORKED!!!!!!
-------------------------------------------------
oCGI.fOut.puts("Content-type: text/html")
oCGI.fOut.puts('')
// oCGI.fOut.puts(responseText)
oCGI.fOut.write(responseText)
-------------------------------------------------

You really know your stuff, I am impressed.

here is the orgins of oCGI. It is actually an array created in WebClass.cc
shipped with dBase for web applications. (see below where it is inserted
into my app.)

It receives and manipulates the data transmitted via stdIn and stdOut, I
hope I have that correct. oCGI an acronym for Common Gateway Interface.

Look at me trying to impress someone as knowlegeable as you, I don't think
that is good idea.

Thanks for all the great help.


The very top of my app.

Set talk OFF // turn off interactive mode
Set century ON // Y2K
_app.errorAction = 3

try

//open webClass
set procedure to sqlWebClass.cc additive

oCGI = new CGISession( )
oCGI.connect( )
Post by Mervyn Bick
oCGI.fOut.puts("Content-type: text/html")
oCGI.fOut.puts('')
oCGI.fOut.puts(responseText)
I think we have the culprit. <g> I don't see where oCGI comes into being
or what it actually is but puts(), which is a synonym for writeln(), is a
method in the File class. When used to write data to a file, puts() adds
a CRLF by default although other terminators can be specified. Write()
only writes the actual string without adding anything so if you use
write() instead ie oCGI.fOut.write(responseText) it may solve your problem.
Mervyn.
Mervyn Bick
2008-11-26 20:58:45 UTC
Permalink
Post by Claus Mygind
Mervyn,
IT WORKED!!!!!!
-------------------------------------------------
oCGI.fOut.puts("Content-type: text/html")
oCGI.fOut.puts('')
// oCGI.fOut.puts(responseText)
oCGI.fOut.write(responseText)
-------------------------------------------------
You really know your stuff, I am impressed.
<BLUSH> <g>

I've been using dBase for about 20 years but I'm actually very much a
learner when it comes to using OODML. I do, however, have an enquiring
mind and, as a means of teaching myself more OODML, I like to try my hand
at solving the problems that present in the newsgroups. Quite often
(most times <g>) my solutions are "clunky" and others (especially Ivar B
<g>) point out better ways of doing things. I appreciate the time they
take because it adds to my education.

I've never done any work on web applications but puts() is an old friend
from the File class that adds a CRLF to strings. You were having problems
with a spurious CRLF so 1+1 =2. <g> (The long way of saying it was just
plain luck that I hit on the answer. <g>)

Anyway, the important thing is that you got it working.

Mervyn.

Claus Mygind
2008-11-26 14:19:28 UTC
Permalink
Nothing to hide here. Here is the entire app code. The app receives two
parameters, the job # JOBID and a department # and employee belongs to
JDEPTID.

Two queries are conducted and strung together for a response separated by
the ~ sign. Within each string I separate the values with the ;

So as to not create an extra empty array element at the end the last ; is
stripped away. Now for those nasty little carriage and line returns.

// Open Query
q = new QUERY()
q.database = db

//execute query to job information
q.sql = 'select jobid, prjctname, jdeptid from job where jobid = "'+
oCGI["JOBID"] +'"'
q.active = true
q.rowset.first()

if not q.rowset.endOfSet
c = q.rowset.fields

responseText = ltrim( str( c['jobid'].value ) )+";"
responseText += trim( c['prjctname'].value )+";"
responseText += trim( c['jdeptid'].value )

cGroup = trim( c['jdeptid'].value )
cDept = oCGI["JDEPTID"]

//execute query to get related templates
q.active = true
q.sql = 'select * from jobTemplates where groupName = "'+ cGroup +'" and
jdeptid = "'+ cDept +'" order by groupKey'
q.active = true
q.rowset.first()

responseText += "~"

if not q.rowset.endOfSet
c = q.rowset.fields

do while not q.rowset.endOfSet

responseText += trim( c['phasecode'].value )+";"

q.rowset.next()

enddo

else

responseText += "none;"

endif


/*
addOn = ""
for n = 1 to len(responseText)
addOn += asc(substr(responseText,n,1))
next

responseText += addOn
*/

// responseText.stuff( at(chr(10)+chr(13)+";", responseText) , 3 )
// responseText = subStr( responseText, 1, ( rat(";",
responseText)-1 ) )

// responseText = substr(responseText,1, len(responseText)-3)
else
responseText = "An error occured;Invalid job #;"
endif
else
responseText = "An error occured;No job # Requested;"
endif

oCGI.fOut.puts("Content-type: text/html")
oCGI.fOut.puts('')
oCGI.fOut.puts(responseText)
Mervyn Bick
2008-11-26 13:46:54 UTC
Permalink
Post by Claus Mygind
I use the code below to assemble a string of values. I separate each value
with the ; so my receiving app can quickly disect the values into an array.
My problem is this, the last value is always returned with the \n\r
attached. Now I can just strip it out like I do with the last ; (see last
line of code below). But I am intrested in knowing why it happens?
do while not q.rowset.endOfSet
responseText += trim( c['phasecode'].value )+";"
q.rowset.next()
enddo
responseText = subStr( responseText, 1, ( rat(";",
responseText)-1 ) )
There is nothing in the code you posted that will add a CRLF to the end of
the string. In any case your last line of code, which strips the final
";", would strip a CRLF at the end of the string as well. If you are
still left with a CRLF at the end of the string then it could be that the
last phasecode value was saved with a CRLF.

As a test to show exactly what is in the string, add the follwing after
the enddo.

? responsetext
for n = 1 to len(responsetext)
? n,substr(responsetext,n,1),asc(substr(responsetext,n,1))
next


Mervyn.
Claus Mygind
2008-11-26 13:58:27 UTC
Permalink
Thanks Mervyn,

I posted in this newsgroup because I thought it was strictly a dBase issue I
was encountering. Actually, my work is in a web app. And I am doing a
blind call to the dBase app on the web server. What that means is I cannot
see the results as they occur only what is returned to the client side of
the equation. Not sure if you are familiar with ajax, but it is a means of
quering your tables with a web browser without refreshing the client screen.

I have never had this issue come up before and I use the same call in other
apps. I say that but obviously I am doing something different that I have
not figured out. So to move on I will be working on bandaid solutions which
are never as good. Because if you don't understand what went wrong you
can't really be sure you fixed it.

Thanks again for the advice, I will try to figure out a way to use it

Claus
Post by Mervyn Bick
Post by Claus Mygind
I use the code below to assemble a string of values. I separate each value
with the ; so my receiving app can quickly disect the values into an array.
My problem is this, the last value is always returned with the \n\r
attached. Now I can just strip it out like I do with the last ; (see last
line of code below). But I am intrested in knowing why it happens?
do while not q.rowset.endOfSet
responseText += trim( c['phasecode'].value )+";"
q.rowset.next()
enddo
responseText = subStr( responseText, 1, ( rat(";",
responseText)-1 ) )
There is nothing in the code you posted that will add a CRLF to the end of
the string. In any case your last line of code, which strips the final
";", would strip a CRLF at the end of the string as well. If you are
still left with a CRLF at the end of the string then it could be that the
last phasecode value was saved with a CRLF.
As a test to show exactly what is in the string, add the follwing after
the enddo.
? responsetext
for n = 1 to len(responsetext)
? n,substr(responsetext,n,1),asc(substr(responsetext,n,1))
next
Mervyn.
Claus Mygind
2008-11-26 14:11:16 UTC
Permalink
This is scary. I searched for a record that would only return one value in
this case 92. Then I used Mervyn's suggestion like this

addOn = ""
for n = 1 to len(responseText)
addOn += asc(substr(responseText,n,1))
next
responseText += addOn

and what I got was this (see the two row array below). why so many
characters when the retuned assembled value would have looked like this
92;\r\n;

first array element
"92"
second array element
"55505553535967111110116114979911632681141051081081051101033283101114118105991011155949494948126575059\r\n"
Mervyn Bick
2008-11-26 15:14:33 UTC
Permalink
Post by Claus Mygind
This is scary. I searched for a record that would only return one value in
this case 92. Then I used Mervyn's suggestion like this
addOn = ""
for n = 1 to len(responseText)
addOn += asc(substr(responseText,n,1))
next
responseText += addOn
...
Post by Claus Mygind
first array element
"92"
second array element
"55505553535967111110116114979911632681141051081081051101033283101114118105991011155949494948126575059\r\n"
Mm. My suggestion was actually to print the character and, next to it,
its ASCII value. I did that because if there was a CRLF at the end of the
string the characters are non-printing but the ASCII value would show what
was there.


I have no idea where your second array element came from. Applying addOn
+= asc(substr(responseText,n,1)) to variable containing 92;\r\n; should
have resulted in 575059921149211059. It's academic as the result is
meaningless anyway.

Mervyn.
Ken Mayer [dBVIPS]
2008-11-26 13:27:14 UTC
Permalink
Post by Claus Mygind
I use the code below to assemble a string of values. I separate each value
with the ; so my receiving app can quickly disect the values into an array.
My problem is this, the last value is always returned with the \n\r
attached. Now I can just strip it out like I do with the last ; (see last
line of code below). But I am intrested in knowing why it happens?
do while not q.rowset.endOfSet
responseText += trim( c['phasecode'].value )+";"
q.rowset.next()
enddo
responseText = subStr( responseText, 1, ( rat(";",
responseText)-1 ) )
Because in Windows (and DOS), you end a line with a carriage return AND
a line feed. The carriage return simply assumes going back to the
beginning of the line, the line feed ensures that you actually move down
a line ...

Ken
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase/dBASEBooks.htm
http://www.goldenstag.net/dbase
Claus Mygind
2008-11-26 13:38:55 UTC
Permalink
Thanks Ken,

I now seem to have some trouble removing the unwanted charcters. Could use
some help

here is my attempts

responseText.stuff( at(chr(10)+chr(13)+";", responseText) , 3 )


This does not seem to work. Does not detect the values. Even tried to
reverse 10 and 13 to no avail.
Greg Hill
2008-11-26 17:04:44 UTC
Permalink
Post by Claus Mygind
I use the code below to assemble a string of values. I separate each value
with the ; so my receiving app can quickly disect the values into an array.
My problem is this, the last value is always returned with the \n\r
attached. Now I can just strip it out like I do with the last ; (see last
line of code below). But I am intrested in knowing why it happens?
do while not q.rowset.endOfSet
responseText += trim( c['phasecode'].value )+";"
q.rowset.next()
enddo
responseText = subStr( responseText, 1, ( rat(";",
responseText)-1 ) )
dBASE uses the semi colon to interpret inline code breaks. Example:

for i = 1 to 1000;?i;enfor

Somehow dBASE is misunderstanding your intended use.

Greg Hill
Claus Mygind
2008-11-26 18:10:41 UTC
Permalink
Greg,

See Mervyn's response 11/26/08 8:53 am. Had to do with output

His response:
"I think we have the culprit. <g> ... puts(), which is a synonym for
writeln(), is a
method in the File class. When used to write data to a file, puts() adds
a CRLF by default although other terminators can be specified. Write()
only writes the actual string without adding anything so if you use
write() instead ie oCGI.fOut.write(responseText) it may solve your problem."

He hit the nail right on the head. changed my oCGI

-------------------------------------------------
oCGI.fOut.puts("Content-type: text/html")
oCGI.fOut.puts('')
// oCGI.fOut.puts(responseText)
oCGI.fOut.write(responseText)
-------------------------------------------------

Claus
Post by Greg Hill
Post by Claus Mygind
I use the code below to assemble a string of values. I separate each value
with the ; so my receiving app can quickly disect the values into an
array. My problem is this, the last value is always returned with the \n\r
attached. Now I can just strip it out like I do with the last ; (see last
line of code below). But I am intrested in knowing why it happens?
do while not q.rowset.endOfSet
responseText += trim( c['phasecode'].value )+";"
q.rowset.next()
enddo
responseText = subStr( responseText, 1, ( rat(";",
responseText)-1 ) )
for i = 1 to 1000;?i;enfor
Somehow dBASE is misunderstanding your intended use.
Greg Hill
Greg Hill
2008-11-26 18:38:19 UTC
Permalink
Post by Claus Mygind
Greg,
See Mervyn's response 11/26/08 8:53 am. Had to do with output
"I think we have the culprit. <g> ... puts(), which is a synonym for
writeln(), is a
method in the File class. When used to write data to a file, puts() adds
a CRLF by default although other terminators can be specified. Write()
only writes the actual string without adding anything so if you use
write() instead ie oCGI.fOut.write(responseText) it may solve your problem."
He hit the nail right on the head. changed my oCGI
-------------------------------------------------
oCGI.fOut.puts("Content-type: text/html")
oCGI.fOut.puts('')
// oCGI.fOut.puts(responseText)
oCGI.fOut.write(responseText)
-------------------------------------------------
Great!
I didn't see anything involving cgi out put from your example or puts or
writein<g>

Greg Hill
Continue reading on narkive:
Loading...