Textarea problem. Missing last line

BlitzPlus Forums/BlitzPlus Programming/Textarea problem. Missing last line

Richard Betson(Posted 2004) [#1]
I'm having a problem getting the last line in a TextArea when I "do not" hit the return key. Like:

Text line one (hit return)
text line two (hit rturn)
text line three (- do not hit return -)

Running the following code yields no text (characters) for the last line in the textarea gadget:

	file=WriteFile(file_req$)
	
	tl=TextAreaLen(textarea1,2)
	
	For i=0 To tl
		tx$=TextAreaText$(textarea1,i,1,2)
		tnl=Len(tx$)
		
		For ii=0 To tnl
			
			If Mid$(tx$,ii,1)=Chr$(10) Or i=tl
				If i=tl Then ii=tnl
				WriteLine file,Mid$(tx$,1,ii-1)
				ii=tnl
			EndIf
		
		Next
		 
		
	Next
	
			
	CloseFile file


Any ideas on whats wrong?

Thanks,


Richard Betson(Posted 2004) [#2]
This might be easier to read:

	file=WriteFile(file_req$)
	
	tl=TextAreaLen(textarea1,2)
	
	For i=0 To tl
		tx$=TextAreaText$(textarea1,i,1,2)
		tnl=Len(tx$)
		
		If i<tl
		
			For ii=0 To tnl					
			
				If Mid$(tx$,ii,1)=Chr$(10)	;Strip line break
			
					WriteLine file,Mid$(tx$,1,ii-1) ;Write result
					ii=tnl
				EndIf
		
			Next
		 
		Else
		
			WriteLine file,tx$
		
				
		EndIf
		
	Next
	
			
	CloseFile file


l8r,


Tiger(Posted 2004) [#3]
If you want to remove Chr$(10) from string, why don't you use the command: Replace(string$,chr$(10),"") ??

Bye.


Richard Betson(Posted 2004) [#4]
@Tiger

I have to strip the line break for a compiler (IDE'ish thing) so although replacing the line break with something else might work it still does not explain why I can not read the last line in a textarea that has no line break in it (see above post).

At the moment it seems if BlitzPlus is not returning a line (actual text within the line) with out a line break in it. I'm really tring to verify this as a bug.

L8r,


Tiger(Posted 2004) [#5]
Try this:
	file=WriteFile(file_req$)
	
	tl=TextAreaLen(textarea1,2)
	
	For i=0 To tl
		tx$=TextAreaText$(textarea1,i,1,2)
		tnl=Len(tx$)
		
			For ii=0 To tnl					
			
				If Mid$(tx$,ii,1)=Chr$(10)	;Strip line break
			
					tx$=Mid$(tx$,1,ii-1) ;Write result
					
				EndIf
		
			Next
		 
		WriteLine file,tx$
		
	Next
	
	
	CloseFile file



Bye.


Richard Betson(Posted 2004) [#6]
Aww ... It worked!

Did you just replace i=tnl with Exit? I guess you can't delcare the for/next var. that way.:)

Anyway Thanks! :),


Tiger(Posted 2004) [#7]
Yes. And I remove one If-Endif and one WriteLine. You can even remove the exit command.

But Its better to do like this:
	file=WriteFile(file_req$)
	
	tl=TextAreaLen(textarea1,2)
	
	For i=0 To tl
		tx$=TextAreaText$(textarea1,i,1,2)
		tx$=Replace(tx$,chr$(10),"")
		WriteLine file,tx$
	Next
	
	
	CloseFile file


Good luck with your project.

Bye.