Jump to content
Developer Wiki and Function Reference Links ×

String Length


michaelk

Recommended Posts

If I have a string variable who's length I haven't bothered to check and I do

 

BeginText;

S1

EndText;

SetTextWrap(LNewObj,TRUE);

 

What determines the width of the text object? 

 

I know I can set it, but when I don't sometimes it goes as wide as the text no matter how long and sometimes it wraps.  Not sure why it does that or how to predict it.

Does it matter if the string is formed by concatenating strings and CHR(13)s?

Link to comment

In my quick test, regardless of the length of a DynArray of Char (I did not test specifically with String), it allways wraps the last character unless you have a CHR(13) in the string which forces a wrap.

 

Procedure Test;

Const S1='abcdefghijklmnopqrstuwxyz26ABCDEFGHIJKLMNOPQRSTUVWXYZ54abcdefghijklmnopqrstuwxyz82ABCDEFGHIJKLMNOPQRSTUVWXYZ110abcdefghijklmnopqrstuwxyz139ABCDEFGHIJKLMNOPQRSTUVWXYZ168abcdefghijklmnopqrstuwxyz197ABCDEFGHIJKLMNOPQRSTUVWXYZ226abcdefghijklmnopqrstuwxyz255ABCDEFGHIJKLMNOPQRSTUVWXYZ284abcdefghijklmnopqrstuwxyz313ABCDEFGHIJKLMNOPQRSTUVWXYZ352';

VAR	S2:DynArray of Char;
BEGIN
	S2:=Concat(SubString(S1,'2',1),CHR(13),SubString(S1,'6',2),CHR(13),S1);
	Moveto(0,0);
	BeginText;
		S2
	EndText;
	SetTextWrap(LNewObj,TRUE);
End;

Run(Test);

 

If you copy this out, be careful of the wrapping. The entire Const line should be on a single line (or at least it was for me).

Link to comment

A few things to consider:

- The text is gong to create using the default text settings, so it may or may not wrap before you tell it to.

- You also need to set the width of the object, otherwise there's not a universal way of determining the wrap (it's not like text wraps to the page boundary).

- You may find that CreateText() is more reliable, both because of the default formatting coming into play and because you have to take into account line breaks and other special characters in the code itself.

  • Like 1
Link to comment

@michaelk,

   At first I thought you exposed a bug, but after several days of visiting this post and rereading your code snippet for the umpteenth time I think your confusion is self inflicted.

 

   If you remove the SetTextWrap(LNewObj, TRUE); line, do you still get unpredictable results? I suspect not, but If so then you may have found a bug, but I have not been able to reproduce it in my very limited testing.

 

   In the following, I use "Text Object" to refer to the text on the page (blue selection handles et al.), and I use "Text Block" to mean the characters of text in your text variable S1. The Text Block's length can only be changed by changing the Font Face, Size, Style, etc., so you can treat it like a constant until you change any of the text's attributes. 

 

   Now back to your code snippet, with the SetTextWrap(LNewObj, TRUE); line in place you are telling VW to force the text block to use Wrapping, even though the length of the text block is unchanged from its default value, and VW responds in kind. Please note that the Text Wrap checkbox in the OIP does not control a real text attribute. It does not save a boolean value with the file and there is no way to set it to be ON by default. What is saved is the WIDTH of the text block. When the calculated text width does not equal the text block width, either because it was changed manually or programmatically, the Wrap Text checkbox gets set. If you CLEAR the Wrap Text checkbox, either manually or programmatically, the text object's width is set to be equal to the calculated width of the text block (which is affected by Font Face, Size, Style, etc.)

 

   What you see on the screen when the Text Object's width does NOT equal the Text Block's length should be predictable. What you see on the screen, when the Text Block's length exactly equals Text Object's width, is affected by what the text block contains.

1) If the Text Block ends in a printable character, the block will wrap the last word (assuming the block contains a white space and words) to the next line.

2) If the Text Block ends with a Space or a Tab character, no visible word wrapping occurs.

3) If the Text Block ends with a Carriage Return, the text block already has a second line, so the first line's appearance is governed by 1) and 2) above.

 

   If you don't care to digest all of the minutiae I've just blathered above, then play with this test code and make you own observations.  

 

PROCEDURE xxx;
{ Script to show how OIP "Wrap Text" affects word wrapping with different string endings. }
{ Change constant "kWordWrap" from FALSE to TRUE to see effects of wrapping. }
{ Document settings are INCHES, Layer Scale = 1, Font = Arial, Point Size = 12.}
{ 28 Oct 2021 - Raymond J Mullin }
CONST
	Tb = chr(9);
	CR = chr(13);
	Sp = chr(32);
	kWordWrap = FALSE;
VAR
	S, S1, S2, S3 :String;

	procedure PlaceText(TxtBlk :String; X, Y :Real);
	Begin
		MoveTo(X, Y);
		BeginText;
			TxtBlk
		EndText;
		SetTextWrap(LNewObj, kWordWrap);
	End;		{ PlaceText }
	
BEGIN
	S := concat('Abysmal echo duck lamps');
	S1 := concat(S, Sp);
	S2 := concat(S, Tb);
	S3 := concat(S, CR);

	PlaceText(S, 0, 0);
	PlaceText(S1, 0, -0.5);
	PlaceText(S2, 0, -1.0);
	PlaceText(S3, 0, -1.5);

	SysBeep;
END;
Run(xxx);

 

HTH,

Raymond

 

PS - I tried @Pat Stanford's example and was able to get the string to word wrap when using Tabs instead of Carriage Returns, but not with Spaces. No idea why.

If you are trying to predict how raw character data will wrap, I leave it to you to investigate further. If you limit yourself to human readable words, you may have better results.

 

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...