Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Wrap Point In EditBox

Status
Not open for further replies.

gbcpastor

Programmer
Jun 12, 2010
77
0
6
US
I used set memowidth to 60 to try to set wrap point in an editbox. I then set the font to a non-proportional font and set the width of the editbox to 60 characters wide. However, while it wraps at 60 on the third line, it doesn't return 4 from memline() until the 10th character of the 4th line of the editbox.

What am I missing?
 
Late? Maybe in Scotland but not in TekTips timescale

Koen, we're a puritanical lot in Scotland. We believe in getting to our beds early. Not like you hedonistic continentals.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
That goes back a bit but that was the original issue. I use a fixed font "Letter Gothic" and set the box to hold exactly 60 characters. But, memlines() wasn't returning the next line until the character counter of the present line reached 70. Weird!

Thanks Olaf. I guess I'll need to come at it from another direction.
 
Actually, it seems to be working for me. This is what I did:

1. Created a form with a single editbox, nothing else.

2. Set the font to a fixed-pitch font and set the width of the editbox so that exactly 60 characters filled the line.

3. Set MEMOWIDTH to 60.

4. In the EditBox's InteractivChange:

[tt]IF MEMLINES(this.Value) > 4
MESSAGEBOX("Too many lines")
ENDIF[/tt]

5. On running the form, I typed random words, each of about 6 - 8 characters, with a space after each. As expected, the moment I typed a character that caused the last word of the 4th line to wrap, the message popped up.

If that's not what you are seeing, there must be something else in your form that we don't know about. You might want to try the above steps - independently of the rest of your application - if only to eliminate any other factors.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Works for me, I don't know what you're doing, but try this and tell me it's not working for you.

Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (d:\temp\editwidth.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   07/30/19 03:26:00 PM
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	Height = 193
	Width = 476
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT edit1 AS editbox WITH ;
		FontBold = .F., ;
		FontItalic = .F., ;
		FontName = "Courier New", ;
		FontOutline = .F., ;
		FontShadow = .F., ;
		FontSize = 9, ;
		FontStrikethru = .F., ;
		FontUnderline = .F., ;
		FontCondense = .F., ;
		FontExtend = .F., ;
		Height = 144, ;
		Left = 12, ;
		MaxLength = 240, ;
		ScrollBars = 0, ;
		Top = 12, ;
		Width = 432, ;
		ControlSource = "cText", ;
		Name = "Edit1"


	PROCEDURE Load
		Set Memowidth To 60
		Create Cursor crsEdit (cText char(240))
		Append Blank
		replace cText with Replicate("1234567890",6)
	ENDPROC


	PROCEDURE edit1.InteractiveChange
		Set Message to Textmerge("Length: <<Len(This.Value)>> Lines: <<Memlines(This.Value)>>")
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************

Bye, Olaf.

Olaf Doschke Software Engineering
 
Wrong_gtqxrc.jpg


This is what happens when I try it as Mike did. The last line is actually 70 characters before the message pops up.

Thanks for trying Mike. I'll have to figure out something else.
 
I'm going to give Olaf's code a try and see if I can stop it at the right place. I'll let you know.
 
This is what happens when I try it as Mike did. The last line is actually 70 characters before the message pops up.

Interesting. I typed exactly the same text as you, and the message popped up as soon as I typed the "o" in "go", which is exactly the 60th character of the third line. There must be something going here that we don't know about.

(By the way, Olaf's code worked for me as well.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sure you haven't SET MEMOWIDTH TO 70? Because that would explain it. This setting I think is per datasession, so you can't just SET MEMOWIDTH once.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Sure you haven't SET MEMOWIDTH TO 70?

That would certainly explain it - although if the form has a private data session, MEMOWIDTH would be set to 50 by default, rather than 70.

In the tests I have been doing, I did the setting in the form's Init.

Later: Yes, I just changed it to 70, and got exactly the same result as Gbcpastor.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I have been setting the memowidth to 60 in the FORM.INIT as well. I thought of that early on. Still working on it thought.
 
You might just double-check that MEMOWIDTH is still set to 60 in the InteractiveChange. I can't think of a good reason why it would have changed, but it is worth checking. Set a breakpoint in the InteractiveChange, then query SET("MEMOWIDTH") in the Debugger's Watch window.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Are you even checking MEMLINES in IteractiveChange? Or when in which code are you checking it?

By the way, as ever so often, it pays to have a Change method called by both InteractiveChange and ProgrammaticChange and in both cases check MEMLINES, of course. A simple strategy would be storing This.Value to a user-defined property LastValidText, in case MEMLINES is lower than 5. And revert the value to that anytime this is not the case.

Bye, Olaf.

Olaf Doschke Software Engineering
 
An easier way of checking that MEMOWIDTH is still correctly set in the InteractiveChange is to adapt the SET MESSAGE command in Olalf's code, as follows:

Code:
Set Message to ;
  Textmerge("Memowidth: <<SET('MEMOWIDTH')>> Length: <<Len(This.Value)>> Lines: <<Memlines(This.Value)>>")

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I've been checking everything in the keypress method and setting the memowidth in the load.

Right now, I have a forced version that's working. it's really rudimentary but, barring something else that correct, I think this will work. It seems like such a simple thing to me.

Thanks for all your help. I'll this thread open till Friday and if no other solution comes up, I'll close it out and leave it as is.
 
This is what I found out. No matter if I put "set memowidth to 60" in the FORM LOAD or FORM INIT, for whatever reason it was resetting the memowidth to 70. When I put "Set MemoWidth to 60" in the KeyPress method for the editbox, it worked fine.

Thanks for all your help. If you ever find a reason for it to reset I'd appreciate it if you'd let me know.

Thanks again;
Pastor Steve
 
Keypress sounds like a natural event to use, but notice that the value then is still not as it will be. That doesn't explain a lag of 10 characters.

I highly recommend to move your checking to Interactivechange instead. Things like pasting (CTRL+P)go under the radar of Keypress, for example, also pasting from the context menu.

Try this modification in my sample code, if you're puzzled how to then prevent getting 5 lines:
Code:
PROCEDURE edit1.InteractiveChange
	 Set Message to Textmerge("Length: <<Len(This.Value)>> Lines: <<Memlines(This.Value)>>")
   If Memlines(This.Value)<5
      This.Tag = This.Value
   Else
      This.Value = This.Tag
      ? Chr(7)   
   Endif
ENDPROC

Bye, Olaf.

Olaf Doschke Software Engineering
 
gbpastor said:
for whatever reason it was resetting the memowidth to 70
Most likely because of inherited code.

Create a breakpoint on the condition SET("MEMOWIDTH") changes:
debugging_z5la89.jpg


Don't forget to keep the debugger window/frame open and you'll find out when this change happens.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top