×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Set Wrap Point In EditBox

Set Wrap Point In EditBox

Set Wrap Point In EditBox

(OP)
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?

RE: Set Wrap Point In EditBox

First, MEMOWIDTH doesn't affect editbox controls. It only affect long strings of text, such as is held in a character or memo field.

Secondly, the width of an editbox is measured in pixels (or sometimes in foxels, but you can ignore that). It has no direct relationship to the number of characters in the line.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

(OP)
Thanks for getting back to me Mike. Since that is the case, I need to know how to make a line wrap happen in an editbox when the length of the line reaches 60, any ideas?

RE: Set Wrap Point In EditBox

Assuming you mean 60 characters (rather than 60 pixels), the only reliable way to do that is by using a fixed-width font (as I think you already know).

Two approaches come to mind. The first is by trail and error. Create a text string of 60 characters (it doesn't matter what the string contains). Paste it into the Value property of your text box. Then resize the edittbox so that the 60 characters all appear on the same line - no more, no less. Then look at the value of the Width property of the edittbox (you can do that in the Debugger). That will give you the value you need.

The other way is to programmatically measure the width of the line in pixels. You can do that by using TXTWIDTH() and FONTMETRIC(). Here is a function that will do that for you: Find the height and width of a text string in pixels.

In fact, the second method will also work with proportional fonts, but in that case the result will be approximate, and will depend on the actual characters that you pass to the function.

Also, when you talk about the text "wrapping", I assume you are using the usual meaning of that word, that is, the line breaking in such a way that every word stays together on a given line - no breaks in mid-word.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

(OP)
Mike, I'm using a non-proportional font now "Letter Gothic" and visually it is wrapping the text at 60 characters. But, when I inquire the line number of the editbox, it returns 3 for the first 10 characters of line 4 then returns 4 after that. I need it to report line 4 as soon as it wraps at 61 characters on line 3.

RE: Set Wrap Point In EditBox

What do you mean when you say "when I inquire the line number of the editbox"? Enquire how?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

Just to further clarify, MLINE() returns a specific line of text, such as the third line (based on your MEMOWIDTH).

MEMLINES() return the total number of lines in the text (again, based on your MEMOWIDTH). Neither of those functions has any direct connection with an editbox, and are independent of the font.

There is also ALINES(), which returns an array, in which each array row contains the contents of one line of the text.

Does that help at all?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

Mr. GbcPastor,
If you use fixed font, and you want to know what is on line 4, which is the 4thline of 60 characters, I believer substr(myField,3*60) is to be used.
Regards,
Koen

RE: Set Wrap Point In EditBox

Quote:

I believer substr(myField,3*60) is to be used

Koen, your are right, except that you would need SUBSTR(MyField, 3*60, 60), otherwise you would get the fourth line and everything after that.

The problem with that approach is that it doesn't know about wordwrap. In other words, it can return a line of text in which the last word is broken in the middle.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

(OP)
My point exactly. Since I'm using a "fix font" and I have the editbox set to 60 characters wide and the memowidth is set to 60, then when I reach the 61st character on the third line, it should wrap to the forth line which it does but MEMLINE() reports it's still on line three until another 10 characters are keyed in.

Example:
1234567890 1234567890 1234567890 1234567890 1234567890 12345
67890 1234

The above says it's all on line 3 and the last ten characters should be line 4.

RE: Set Wrap Point In EditBox

Quote:

MEMLINE() reports it's still on line three until another 10 characters are keyed in

(Emphasis added.)

Ah, that's the answer. You are testing MEMLINE() while the use is still editing the text. It can't know the final contents of the line until the user has hit the spacebar after the tenth character. That's why you are getting the behaviour you are seeing.

Perhaps if you tell us exactly what you overall goal is, we might be able to suggest a solution.

Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

(OP)
Easy enough you would think Mike. I have a small form containing nothing but an edit box 60 characters wide and 4 lines deep. There is an OK button on the bottom. The editbox is to allow no more than a total of 240 characters and no more than 4 lines. The control is linked to a character field called notes2 c(240). That's it.

RE: Set Wrap Point In EditBox

For a start, you could set the EditBox's MaxLength to 240. That would solve the first part of the problem.

As for the check on the number of lines, I would do that after the editing is complete - perhaps in the EditBox's LostFocus. At that point, MEMLINES() should return the correct value.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

Quote:

I would do that after the editing is complete - perhaps in the EditBox's LostFocus.

On second thoughts, I can see why you wouldn't want to do that. You want to prevent the text going over four lines, not merely advise the user after the event.

It's getting late in the evening here now. I'm going to clock off. I'll be back in the morning.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

MEMLINES() expects the name of a memo field, how do you use that if your field is C(240)? If you copy over the editbox value into a memo field, you can apply it, but it'll return the number of lines the whole string has, not a "current" line number.

SET MEMOWIDTH help topic says it respects the font setting of _screen, quote:

Quote (VFP help)

If output is directed to the main Visual FoxPro window, the width of the output is determined by the font for the main Visual FoxPro window. If output is directed to a user-defined window, the width of the output is determined by the font for the user-defined window.

I'm not sure what to make of that, as MEMOWIDTH still is about the number of characters.


I made a small experiment. This is what I get:


The Editbox is set up to allow exactly 60 characters of monospaces Courier New text in that font size. I copied that Editbox content to a memo field os a cursor, SET MEMOWIDTH TO 60 (before even creating the cursor).

You see I didn't change the _Screen font to Courier New, too. The output directly below the Editbox is from simply printing that memo field. The output after '---' is done with MLINE(memo,1) to MLINE(memo,5). I think the output of the memo itself with ? memo wraps differently, because of that. MLINE() seems to work 1:1 and by the way MEMLINES() returns 5, too.

From that experiment, MEMLINES seems ok, I'd perhaps rely more on MLINE reproducing the lines. Both also seem to work when you introduce manual line breaks with ENTER. Anyway, more than 4 lines fit in char(240) with manual line breaks. If you want to limit this to 4 lines, then checking MEMLINES seems ok, once you go for a monospaced font.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Set Wrap Point In EditBox

If you get different results, please check, if your editbox really gets 60 characters into one line, the scrollbar counts to the editbox width, which could break it.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Set Wrap Point In EditBox

Hi Mike,

Late? Maybe in Scotland but not in TekTips timescale smile2

RE: Set Wrap Point In EditBox

(OP)
I was sure between you and Mike I would find a solution. But I guess I will have to come up with another approach. I've done all you did here and none of that is a solution.

I think I'll go at it doing a character count and count each Chr(13) as length of the line padded to 60. I'll see if that works. I have the scrollbars turned off so they don't affect what is allowed in each line.

Let me know if you guys come up with something that works, and I'll do the same.

RE: Set Wrap Point In EditBox

Well, MEMLINES(memofield) works for me, or checking whether LEN(MEMLINE(memofield,5))>0.
But the editbox content must be saved to a memo field. Even if just for checking.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Set Wrap Point In EditBox

OK, checked once more, you don't need a memo field. Anyway, does REPLICATE("W",60) fit into one line? I needed to set the EditBox width to 60*width by font metric plus scrollbar width (you don't need that) plus 12 or so extra pixels. So even a plain Editbox without scrollbars has pixels for border and some extra padding pixels as a margin of the inner text to the EditBox borders.

If that is correct you get word wrap at the exact points when MEMLINES() also computes more lines.

Just to state the obvious: MEMLINES is all about counting characters according to SET MEMOWIDTH, also recognizes carriage return. The Editbox wrapping is all about wrapping for pixel width, independent of MEMOWIDTH.

You don't have to set the Editbox to exactly the correct width, as soon as a 61st character wraps over this will wrap the same way as MEMLINES will count, but as I have shown in a screenshot: Doing ? to print the Editbox value can have more lines than the Editbox shows.

More things to realize: InteractiveChange would be a good moment to check MEMLINES. In that event you better check MEMLINES of the Editbox.Value than MEMLINES(field), because the field only updates when the Editbox valid allows writing back to the ConotrolSource, ie when you change focus to another control.

Then your non-proportional font might not really be non-proportional. Have you simply tried with "Courier New" just to ensure it's not the font?

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Set Wrap Point In EditBox

Quote:

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

RE: Set Wrap Point In EditBox

(OP)
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.

RE: Set Wrap Point In EditBox

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:

IF MEMLINES(this.Value) > 4
MESSAGEBOX("Too many lines")
ENDIF


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

RE: Set Wrap Point In EditBox

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
https://www.doschke.name

RE: Set Wrap Point In EditBox

(OP)


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.

RE: Set Wrap Point In EditBox

(OP)
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.

RE: Set Wrap Point In EditBox

Quote:

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

RE: Set Wrap Point In EditBox

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
https://www.doschke.name

RE: Set Wrap Point In EditBox

Quote:

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

RE: Set Wrap Point In EditBox

(OP)
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.

RE: Set Wrap Point In EditBox

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

RE: Set Wrap Point In EditBox

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
https://www.doschke.name

RE: Set Wrap Point In EditBox

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

RE: Set Wrap Point In EditBox

(OP)
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.

RE: Set Wrap Point In EditBox

Please let us know if you find out why it wasn't working. The information could be useful to others (and to satisfy my curiosity).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Set Wrap Point In EditBox

(OP)
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

RE: Set Wrap Point In EditBox

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
https://www.doschke.name

RE: Set Wrap Point In EditBox

Quote (gbpastor)

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:


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
https://www.doschke.name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close