How to word-wrap a long line - Solved

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Djek
Pro Scripter
Posts: 148
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

How to word-wrap a long line - Solved

Post by Djek » Sun May 02, 2021 5:46 pm

hi all,
Does anyone know, a possible way, to covert a long line (approx 100 chars)
into a word-wrap formatted separate lines. (approx 22 chars wide)
In this case it are ingredients, all separated with space.
so input line could be:
Milk, Butter, Water, Nuts, Lemon, Sugar, Salt, Peanuts, Oil, Egg
and the output would become:
Milk, Butter, Water,
Nuts, Lemon, Sugar,
Salt, Peanuts, Oil,
Egg
The lines seperated by a CRLF

I have tried to load the input into a Memo, and put the "Wordwrap" on.
For visual/the looks, it works, but if i want to export the wordwrapped output out of the Memo,
then the format reverts back to the long line without the Carridge returns.
Ideal the output would contain a CRLF on the wrapped end of the line.
In the Memo object properties help-file it says:
WordWrap
Determines whether the edit control inserts soft carriage returns so text wraps at the right margin.

But a string replace wich replaces %CR% with %CRLF% does not find the %CR%
Or could a "soft carridge return" be an other character?
Or can i get the first line, second line, etc out the the Memobox?

Thanks in advance,
Djek
Last edited by Djek on Tue May 04, 2021 10:15 am, edited 1 time in total.

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: How to word-wrap a long line

Post by Grovkillen » Sun May 02, 2021 6:01 pm

Can't you use the HTML element for that?
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Djek
Pro Scripter
Posts: 148
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: How to word-wrap a long line

Post by Djek » Sun May 02, 2021 6:08 pm

thanks for responding, Grovkillen,
but HTML element; I dont get the way to use this?
Could you explain or put me on the right track?
Djek

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: How to word-wrap a long line

Post by Grovkillen » Sun May 02, 2021 7:26 pm

You could then use the <br> tag to have line breaks and those are quite easy to remove from the string.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Djek
Pro Scripter
Posts: 148
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: How to word-wrap a long line

Post by Djek » Sun May 02, 2021 8:36 pm

Image

Yes, it has the same effect as the Memobox has, but how can i extract these lines out of the HTML dialog ?

Thanks
Djek

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: How to word-wrap a long line

Post by Grovkillen » Mon May 03, 2021 7:27 am

Oh, I see that you cannot get the HTML data back... that's weird. Perhaps Marcus could shed some light on why that is.

As a proof of the "bug":

Code: Select all


Dialog>Dialog1
object Dialog1: TForm
  Left = -2797
  Top = -1168
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 211
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSHTMLViewer1: tMSHTMLViewer
    Left = 8
    Top = 5
    TabOrder = 8
    BorderStyle = htFocused
    DefFontName = 'Times New Roman'
    DefPreFontName = 'Courier New'
    HistoryMaxCount = 0
    NoSelect = False
    PrintMarginBottom = 2.000000000000000000
    PrintMarginLeft = 2.000000000000000000
    PrintMarginRight = 2.000000000000000000
    PrintMarginTop = 2.000000000000000000
    PrintScale = 1.000000000000000000
  end
end
EndDialog>Dialog1

SetDialogProperty>Dialog1,MSHTMLViewer1,HTML,This is<br>a list
GetDialogProperty>Dialog1,MSHTMLViewer1,HTML,WORDWRAP_string

Show>Dialog1
Wait>2


//This was how I imagine the clean up would look like:
StringReplace>WORDWRAP_string,<br>%SPACE%,%SPACE%,WORDWRAP_string
StringReplace>WORDWRAP_string,<br>,%SPACE%,WORDWRAP_string

Message>WORDWRAP_string
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1378
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How to word-wrap a long line

Post by Dorian (MJT support) » Mon May 03, 2021 9:16 am

Have noted this for Marcus.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Marcus Tettmar
Site Admin
Posts: 7393
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to word-wrap a long line

Post by Marcus Tettmar » Mon May 03, 2021 9:37 am

I am having a hard time following this.

Wordwrap does not modify the text. It just describes how that text should fit in the window. I think you'll find this is the same for all editors. E.g. if you were using a text editor like Notepad and you enabled wordwrap it would mean you would see all the text wrapped, without having to scroll horizontally but it does NOT mean the text is modified. The raw text remains the same and you'd be able to verify that by echoing out to the command line or editing with another editor.

So I am confused here with the idea that you want to enable wordwrap and then expect to see the text modified when you retrieve it from the control.

Furthermore an HTML viewer is a VIEWER. It is not designed for modifying the text, so when you retrieve the text you sent to it you get exactly what you sent into it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: How to word-wrap a long line

Post by Grovkillen » Mon May 03, 2021 11:59 am

Marcus Tettmar wrote:
Mon May 03, 2021 9:37 am
Furthermore an HTML viewer is a VIEWER. It is not designed for modifying the text, so when you retrieve the text you sent to it you get exactly what you sent into it.
You mean that I'm not supposed to get back the data sent to the viewer using the GetDialogProperty command?
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to word-wrap a long line

Post by JRL » Mon May 03, 2021 2:57 pm

Does anyone know, a possible way, to covert a long line (approx 100 chars)
into a word-wrap formatted separate lines. (approx 22 chars wide)
Here's one way: This won't deal with words that are longer than the specified line length. It will just put the long word on one line.

Code: Select all

Let>vStr=Milk, Butter, Water, Nuts, Lemon, Sugar, Salt, Peanuts, Oil, Egg
Let>MaxLineLength=22
Separate>vStr,%space%,vItem

Let>msg_Ypos=0
Message>

Let>vTestList=
Let>vLastList=
Let>vNewList=
Length>vNewList,vLen
Let>kk=0
Repeat>kk
  Add>kk,1
  Let>value=vItem_%kk%
  Let>vTestList=%vLastList%%value%%space%
  Length>vTestList,vTestRes
  If>vTestRes>MaxLineLength
    Let>vNewList=%vNewList%%vLastList%%crlf%
    If>%kk%=%vItem_Count%
      Let>vLastList=%value%
    Else
      Let>vLastList=%value%%space%
    EndIf
    Goto>EndOfLoop
  Else
    If>%kk%=%vItem_Count%
      Let>vLastList=%vLastList%%value%
    Else
      Let>vLastList=%vLastList%%value%%space%
    EndIf
  EndIf
  Label>EndOfLoop
  SetControlText>Macro Scheduler Message,TMemo,1,vNewList
Until>kk={%vItem_Count%}

Let>vNewList=%vNewList%%vLastList%%crlf%

SetControlText>Macro Scheduler Message,TMemo,1,vNewList

User avatar
Djek
Pro Scripter
Posts: 148
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: How to word-wrap a long line

Post by Djek » Tue May 04, 2021 9:52 am

Thanks Marcus, Dorian and of course JRL
I had a guess that i could use a dialog object to wordwrap a string into broken-up parts of that string,
No problem if it can not. It would be convenient if it could, because im always glad if there is a "lazy"option!

But JRL; Thanks (again!) for your solution to my problem, it works perfect !
Thanks all for helping me ! :D

Kind regards,
Djek

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to word-wrap a long line - Solved

Post by JRL » Wed May 05, 2021 6:58 pm

I have tried to load the input into a Memo, and put the "Wordwrap" on.
For visual/the looks, it works, but if i want to export the wordwrapped output out of the Memo,
then the format reverts back to the long line without the Carridge returns.
Ideal the output would contain a CRLF on the wrapped end of the line.
My take on the above.

Use GetTextInRect to add those pesky Carriage Return/Line Feeds.

Stretch the window to change the wrap. May need to stretch the message window to see your results as the message window does its own wordwrapping.

Can only process what will fit on your screen.


Code: Select all

Let>vStr=Milk, Butter, Water, Nuts, Lemon, Sugar, Salt, Peanuts, Oil, Egg

GetTextinit

Dialog>Dialog1
object Dialog1: TForm
  BorderStyle = bsSizeToolWin
  Caption = 'WordWrap'
  ClientHeight = 152
  ClientWidth = 120
  Position = poScreenCenter
  object MSMemo1: tMSMemo
    Left = 5
    Top = 5
    Width = 110
    Height = 100
    WordWrap = True
    Anchors = [akLeft, akTop, akRight, akBottom]
  end
  object MSButton1: tMSButton
    Left = 22
    Top = 121
    Width = 75
    Height = 25
    Caption = 'Process'
    Anchors = [akBottom]
  end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,srtProcess
SetDialogProperty>Dialog1,MSMemo1,Text,vStr
Show>Dialog1,

SRT>srtProcess
  Let>WIN_USEHANDLE=1
  GetWindowPos>Dialog1.msmemo1.handle,WinX,WinY
  GetWindowSize>Dialog1.msmemo1.handle,WinW,WinH
  Let>WIN_USEHANDLE=0
  Add>WinW,WinX
  Add>WinH,WinY
  GetTextInRect>WinX,WinY,WinW,WinH,vRes
  Wait>0.3
  MDL>vRes
END>srtProcess

User avatar
Djek
Pro Scripter
Posts: 148
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: How to word-wrap a long line - Solved

Post by Djek » Thu May 06, 2021 6:49 am

JRL ...
YOU truly are the greatest ...!
This is the ultimate fitting solution the way i spend hours on to realize and I could not.
Because, while fitting in the Memodialog, this is "whatyouseeiswhatyouget" output !
I wish, I had some of your creativity, because it is not difficult if you look at it, and I knew what i wanted to do, and you showed the way to do it.
Thanks,
Djek

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to word-wrap a long line - Solved

Post by JRL » Thu May 06, 2021 1:31 pm

Djek,
Thank you for your kind words. It is fun to help and even more fun when the expended effort is acknowledged.

I got to thinking about the first solution I presented and how it is character based. Depending on how you use the output that might be fine. The sticking point was the fact that very few people have their applications set to a mono-spaced font. Most modern fonts use much more space for an uppercase "W" than for a lower case "i". You could easily create a perfectly good character based "Wrapped" text string and not like the look of it after you paste it into your application. Your original idea made more sense because you'd be able to see the exact result (WYSIWYG). If needed, you could even adjust the memo box font and text size to match the application you're dropping the text into.

Now I have a question probably only Support can answer. It took me way longer to develop this little script than it should have. I can only run a gettext function about half a dozen times before I get an "out of resources" message. Macro Scheduler is dead in the water at that point. Killing the msched.exe in Task Manager wipes out Macros.dat every time. My home computer has 4 Xeon processors and 32 Gb of RAM and the only app running (other than startup processes) is Macro Scheduler. I can't possibly be out of resources. What can I do to remedy this "out of resources" message? Does anyone else have this issue?

Edit: I see that this issue was already reported earlier this year. I don't use text capture so was not aware there was an issue. I'm using MS version 15.0.12. Maybe the latest version fixes this.
viewtopic.php?f=2&t=10457


Edit 2: Updated to version 15.0.18 and seem to no longer have the problem. Sorry to have been behind in my forum reading and my updates.

Another question. What's the difference between using GetTextInit and GetTextReset? They both seem to work the same.

Thank you,
Dick

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts