AutoHotkey Community

It is currently May 27th, 2012, 7:41 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: September 7th, 2006, 4:13 pm 
I made a script that sends text to a AS400 Computer over a Terminalprogram. Therefor I had to wrap text (and put this text in special form: Ctrl as Enter,linenumbers etc ..)

So I searched for a wrap algorithm. I found Text wrapper.ahk but it was a little bit to complicated for me. Now I have made my own wrap function.

Code:


wrap(String,maxWrapLength,separator = "",showSeparator = "") {
;    global endChar
    endChar := "`n"
    beforewrap := ""
    str1 := ""
   
    StringReplace, String1, String, `r`n, %A_Space%, All
    StringReplace, String1, String1, `n,%A_Space% , All
   
    If (separator != "")
        StringReplace, String1, String1, %separator%,%endChar%%separator%, All
    Loop   Parse, String1, `n
      {
        str :=""
        length := 0
        line := A_loopfield
        Loop Parse, line, %A_Space%
          {
            beforewrap := str
            str := str  . A_loopfield . A_Space
            lengthLoopfield := StrLen(A_loopfield)
            length := length + lengthLoopfield +1
            If length > %maxWrapLength%
              {
                str := beforewrap . endChar . A_loopfield . A_Space
                length := StrLen(A_loopfield) +1
              }
          }
        If (str1 = "")
            str1 := str1  . str
        Else
            str1 := str1 . endChar . str
      }
    If (showSeparator = "0")
        StringReplace, str1, str1,%separator%,, All
     Return str1
  }


Code:
  TexttoWrap = hallo1 ha+l++lo2 hallo3 hallo4 hallo5

  test := wrap(TexttoWrap,20,"+",0 )
  MsgBox, ::::wrap:::: `n`n%test%
 
  MsgBox, % "::::wrap::::`n`n" wrap(TexttoWrap,20,"+",1 )

 
  MsgBox, % "::::wrap::::`n`n" wrap(TexttoWrap,20,"",1 )



I hope someone will find this helpful.
If you find Errors or a better way to do this, please comment it.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2006, 4:23 pm 
Would you mind to put 'AS400' to the subject line. Will get the additional focus of those who have to work with such an environment. Thx for sharing this. :D


Report this post
Top
  
Reply with quote  
PostPosted: September 7th, 2006, 4:39 pm 
@ BoBo
Thanks for your Reply.
I hope this is the correct way to put the word AS400 in the subject.
:D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2006, 4:46 pm 
but of course, in the initial post :wink: so it will be shown as the threads headline (a moderator can do that on your behalf).


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2006, 10:51 am 
Brilliant! Thx. :D


Report this post
Top
  
Reply with quote  
PostPosted: September 8th, 2006, 11:41 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Nice and useful script.
Haichen wrote:
If you find Errors or a better way to do this, please comment it.
Here is my take:
Code:
wrap(String, maxWrapLength, separator = "", showSeparator = "")
{
   endChar := "`n"
   str1 := ""

   StringReplace String1, String, `r`n, %A_Space%, All
   StringReplace String1, String1, `n, %A_Space%, All

   If (separator != "")
      StringReplace, String1, String1, %separator%, %endChar%%separator%, All
   Loop Parse, String1, `n
   {
      str := ""
      length := 0
      line := A_loopfield
      Loop Parse, line, %A_Space%
      {
         lengthLoopfield := StrLen(A_loopfield)
         length := length + lengthLoopfield +1
         If (length > maxWrapLength)
         {
            str := str . endChar . A_loopfield . A_Space
            length := lengthLoopfield + 1
         }
         Else
         {
            str := str . A_loopfield . A_Space
         }
      }
      If (str1 = "")
         str1 := str
      Else
         str1 := str1 .  endChar .  str
   }
   If (showSeparator = "")
      StringReplace str1, str1, %separator%, , All
   Return str1
}

textToWrap =
(
Variable types: AutoHotkey has no explicitly defined variable types; all variables are stored as
character strings. However, a variable containing only digits (with an optional decimal point) is
automatically converted to a number when a math operation or comparison requires it.
Conversely, the result of a math operation is converted back to a string when it needs to be stored
in a variable.
~~
~~Variable scope and declarations: With the exception of local variables in functions, all variables
are global; that is, their contents may be read or altered by any part of the script. In addition,
variables are not declared; they come into existence simply by using them (and each variable
starts off empty/blank).
~~
~~Variable names: Variable names are not case sensitive (for example, CurrentDate is the same as
currentdate). Variable names may be up to 254 characters long and may consist of letters,
numbers and the following punctuation: # _ @ $ ? [ ]
)
MsgBox % wrap(textToWrap, 50, "~~", false)
MsgBox % wrap(textToWrap, 25, "~~", false)
Basically, I avoid some unneeded operations.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2006, 11:26 pm 
@BoBo Thanks for your friendly comments!
@PhiLho; Nice to see your Version.
That was my first try; The word after maxLength was the first of the new Line. But then I made somewhere a mistake. I wasn't able to find the error.
Now I see: I was near.

Thanks a lot!!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 24th, 2006, 9:57 am 
Offline

Joined: September 23rd, 2006, 1:58 pm
Posts: 149
Quote:
I made a script that sends text to a AS400 Computer over a Terminalprogram.


As i have no AS400, the script itself is of no use for me personally, but
what i am intersted in, is the script yo wrote to send text via a terminal program.

Is the sending script ahk, too? And what terminal program did you use?
Can you post the sending script anyway? Because as far as i can see, the only posted method to send data to another computer is this highly complicated script that uses NetCat.
If your script uses a general terminalprogram (hopefully freeware) it possibly very interesting for everyone, who wants his script to communicate with another script on a different computer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 24th, 2006, 10:59 am 
Thanks for your question,
The Script I wrote only fills out masks and so there is no communication with the AS400 (no Answer)..
When you work without my Script you have to put in a Linenumber, send this Number to the AS400 and then you can write text. But only 60 character, there is no wrap and only one Line. You have to look for your own that there are not more characters or the text will be cut.
After you wrote the text, you can send the text to the AS400 (by the STRG Key; it simulate a Key named Datenfreigabe). After that you can input a new Line number.

02STRGtext text text text text text text text text text text textSTRG
03STRGtext text text text text text text text text text text textSTRG
...
Because its not very funny to put a lot of text in the maschine I made a special Textformatter.
The Program formats the Text from a Inputcontrol as you see above and puts it via send into the Terminalprogram, which automatically send the text to the AS400 (STRG is the signal for the Terminalprogram so send the Text)
http://www.mochasoft.dk/tn5250.htm
Hope I make it clear.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], nothing, Yahoo [Bot] and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group