 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Haichen Guest
|
Posted: Thu Sep 07, 2006 3:13 pm Post subject: Send a wrapped text to an AS400 computer; a wrap function |
|
|
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. |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Thu Sep 07, 2006 3:23 pm Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
Haichen Guest
|
Posted: Thu Sep 07, 2006 3:39 pm Post subject: send a wrapped text to a AS400-Computer; a wrap funtion |
|
|
@ BoBo
Thanks for your Reply.
I hope this is the correct way to put the word AS400 in the subject.
 |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Thu Sep 07, 2006 3:46 pm Post subject: |
|
|
but of course, in the initial post so it will be shown as the threads headline (a moderator can do that on your behalf). |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Fri Sep 08, 2006 9:51 am Post subject: |
|
|
Brilliant! Thx.  |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Fri Sep 08, 2006 10:41 am Post subject: Re: Send a wrapped text to an AS400 computer; a wrap functio |
|
|
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. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Haichen Guest
|
Posted: Fri Sep 08, 2006 10:26 pm Post subject: |
|
|
@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!! |
|
| Back to top |
|
 |
Zed Gecko
Joined: 23 Sep 2006 Posts: 149
|
Posted: Sun Sep 24, 2006 8:57 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
haichen Guest
|
Posted: Sun Sep 24, 2006 9:59 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|