qwert Posted April 10, 2008 Share Posted April 10, 2008 I have an text entry control defined as follows: GUICtrlCreateEdit("Test Field", 10, 10, 200, 160, $ES_WANTRETURN + $ES_MULTILINE + $ES_RIGHT) Every thing works fine and user entries are displayed as expected. Occasionally, however, I need to print the field. Right now, I'm simply writing the field to a text file and printing that file -- but it loses its right justification and prints left justified. Is there any feature to either 1) directly print the right justified edit field or 2) specify the justification when writing the text file? Building a blank-padded text file is the only technique I can think of, but that is difficult to do with proportional fonts. Hopefully, this has been "invented" -- but I've not been able to locate a solution. Thanks for any assistance. Link to comment Share on other sites More sharing options...
GEOSoft Posted April 10, 2008 Share Posted April 10, 2008 I have an text entry control defined as follows: GUICtrlCreateEdit("Test Field", 10, 10, 200, 160, $ES_WANTRETURN + $ES_MULTILINE + $ES_RIGHT) Every thing works fine and user entries are displayed as expected. Occasionally, however, I need to print the field. Right now, I'm simply writing the field to a text file and printing that file -- but it loses its right justification and prints left justified. Is there any feature to either 1) directly print the right justified edit field or 2) specify the justification when writing the text file? Building a blank-padded text file is the only technique I can think of, but that is difficult to do with proportional fonts. Hopefully, this has been "invented" -- but I've not been able to locate a solution. Thanks for any assistance.Plain text files have no formatting therefore no justification. You might be better to look at writing it to an RTF file. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
martin Posted April 10, 2008 Share Posted April 10, 2008 Plain text files have no formatting therefore no justification. You might be better to look at writing it to an RTF file.Also have a look at big daddy's Word udf.My print udf could do what you want. For each line in the edit can can get the width of the text on the page, and the height, then print it at the correct postion using these functions_PrintSetFont_PrintGetextWidth_PrintGetTextHeight_PrintTextThere is a link in my signature. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
DaleHohm Posted April 10, 2008 Share Posted April 10, 2008 Or... take a look at the StringFormat command. For Example: ConsoleWrite(StringFormat("[%80s]\n", "This is Right Justified")) produces: [ This is Right Justified] Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
qwert Posted April 10, 2008 Author Share Posted April 10, 2008 Or... take a look at the StringFormat command.Thanks for each of the suggestions. From what I've read so far, I would summarize the four alternatives as follows: Word udf -- somewhat of a high-end approach, with lots of formatting capabilities Write RTF -- a mid-level solution that requires learning a bit about rich text Printing udf -- an easy-to-implement, mid-level approach that can certainly cover the basics Write/Read Console -- the simplest method to use, but very limited. Since I only have the one requirement (right justification), it appears the console write/read is my best bet. (My largest text block will be on the order of 50 lines.) However, my attempt at a simple test caused my test script to permanently pause: ConsoleWrite(StringFormat("[%16s]\n", "This is a test")) $contents = ConsoleRead() MsgBox(0, "Read: ", $contents) Do you know what the problem might be? Also, it appears that I'll have to write each of the user entered lines of text separately. Is that correct? Thanks for any assistance. Link to comment Share on other sites More sharing options...
GEOSoft Posted April 10, 2008 Share Posted April 10, 2008 Thanks for each of the suggestions. From what I've read so far, I would summarize the four alternatives as follows: Word udf -- somewhat of a high-end approach, with lots of formatting capabilities Write RTF -- a mid-level solution that requires learning a bit about rich text Printing udf -- an easy-to-implement, mid-level approach that can certainly cover the basics Write/Read Console -- the simplest method to use, but very limited. Since I only have the one requirement (right justification), it appears the console write/read is my best bet. (My largest text block will be on the order of 50 lines.) However, my attempt at a simple test caused my test script to permanently pause: ConsoleWrite(StringFormat("[%16s]\n", "This is a test")) $contents = ConsoleRead() MsgBox(0, "Read: ", $contents) Do you know what the problem might be? Also, it appears that I'll have to write each of the user entered lines of text separately. Is that correct? Thanks for any assistance.Read the edit contents to an array first. $Output = StringSplit(StringStripCR(GUICtrlRead($Edit)), @LF) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
qwert Posted April 10, 2008 Author Share Posted April 10, 2008 Read the edit contents to an array first. $Output = StringSplit(StringStripCR(GUICtrlRead($Edit)), @LF)I tried your suggestion in the following sequence, but it still hung when I had three lines in the $Edit field: $Output = StringSplit(StringStripCR(GUICtrlRead($Edit)), @LF) MsgBox(0, "Result: ", $Output[0]) ConsoleWrite(StringFormat("[%16s]\n", $Output)) $contents = ConsoleRead() MsgBox(0, "Read: ", $contents) I also inserted the "Result:" message box and found $Output[0] = "3" when my 3-line $Edit contained: 123 456 test So I'm sure I don't understand the mechanics of this. The documentation says the ConsoleRead will be "with wait" if no characters are available, so I assume the ConsoleWrite is not working, but I don't see why it wouldn't retrieve at least the "3" in my test. And for that matter, why did my previous example (which was trying to mimic what Dale suggested) not produce at least that one test line? I would appreciate a brief summary of what the sequence is supposed to accomplish -- or maybe a short working example? Thanks. Link to comment Share on other sites More sharing options...
martin Posted April 10, 2008 Share Posted April 10, 2008 I tried your suggestion in the following sequence, but it still hung when I had three lines in the $Edit field: $Output = StringSplit(StringStripCR(GUICtrlRead($Edit)), @LF) MsgBox(0, "Result: ", $Output[0]) ConsoleWrite(StringFormat("[%16s]\n", $Output)) $contents = ConsoleRead() MsgBox(0, "Read: ", $contents) I also inserted the "Result:" message box and found $Output[0] = "3" when my 3-line $Edit contained: 123 456 test So I'm sure I don't understand the mechanics of this. The documentation says the ConsoleRead will be "with wait" if no characters are available, so I assume the ConsoleWrite is not working, but I don't see why it wouldn't retrieve at least the "3" in my test. And for that matter, why did my previous example (which was trying to mimic what Dale suggested) not produce at least that one test line? I would appreciate a brief summary of what the sequence is supposed to accomplish -- or maybe a short working example? Thanks. StringSplit returns an array but the first element, $Output[0] in your case, is the number of substrings. The substrings from the original string are $Output[1],..[2],...[3]. Then you need $Output = StringSplit(StringStripCR(GUICtrlRead($Edit)), @LF) MsgBox(0, "Result: ", $Output[0]) ConsoleWrite(StringFormat("[%16s]\n", $Output[1]));or [2] or [3] etc $contents = ConsoleRead() MsgBox(0, "Read: ", $contents) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
qwert Posted April 10, 2008 Author Share Posted April 10, 2008 StringSplit returns an array but the first element, $Output[0] in your case, is the number of substrings.Oh. Well, that explains it. I'll rework my test to loop on the ConsoleWrite side using $Output[0] as the loop count. Having "123" as my first line put me on the wrong path interpreting the "3". Thanks for helping me with this. Link to comment Share on other sites More sharing options...
qwert Posted April 10, 2008 Author Share Posted April 10, 2008 Well my enthusiasm for this solution is waning. The ConsoleRead never returns. I've confirmed that everything up to that point executes properly. I'm beginning to think that this won't work because of this line in the documentation:ConsoleRead ... is normally used by console applications to read input from a parent process.Does this mean it can't work within the same process? I don't know what else to try. Link to comment Share on other sites More sharing options...
Squirrely1 Posted April 10, 2008 Share Posted April 10, 2008 (edited) qwert - carefully study the example at the bottom of the page in help file under ConsoleRead. You have to call it in a loop and it will still only work if the script is compiled. I would try martin's print udf - even though you have to install his dll - it seems to target just the solution you need. Edited April 10, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
qwert Posted April 10, 2008 Author Share Posted April 10, 2008 You have to call it in a loop and it will still only work if the script is compiled.That certainly would explain what I've seen.But this is the only "example" in my copy of v3.2.10.0:;Example to be provided by DaveFCan you point me to another one? Link to comment Share on other sites More sharing options...
DaleHohm Posted April 10, 2008 Share Posted April 10, 2008 I wasn't trying to get you to focus on the ConsoleWrite, but on the StringFormat What are you trying to accomplish? Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
qwert Posted April 11, 2008 Author Share Posted April 11, 2008 What are you trying to accomplish?I'm simply trying to print a multi-line, right-justified edit field on a piece of paper -- in as simple a way as possible. Link to comment Share on other sites More sharing options...
Squirrely1 Posted April 11, 2008 Share Posted April 11, 2008 qwerty - I recommend you toggle over to the latest beta. Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
qwert Posted April 11, 2008 Author Share Posted April 11, 2008 qwerty - I recommend you toggle over to the latest beta.Can you explain? That seems rather drastic, since I'm trying to build a production script for distribution. I've always shied away from building on anything other than the latest official release. Are there specific new features that would solve this right-justify problem? And is a new release planned soon -- so that I would only be on the beta for a short while? Link to comment Share on other sites More sharing options...
Squirrely1 Posted April 11, 2008 Share Posted April 11, 2008 (edited) This page always has the latest beta, which is now called:"autoit-v3.2.11.5-beta-setup.exe"After installing it, put a shortcut to the beta help file on your desktop, with this target:"C:\Program Files\AutoIt3\Beta\AutoIt.chm"Here is code to build an rtf file that is right-justified. Just put your text in the $paragraph variable:$file = "Document2.rtf" $paragraph = "Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot. Squirrely business is afoot." FileWriteLine($file, "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}") FileWriteLine($file, "{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\qr\f0\fs20 " & $paragraph & "\par") FileWriteLine($file, "}") FileWriteLine($file, Chr(0))The way I built this is to make a .rtf file in Wordpad, right-justify it - but not change the font from the default, then I opened the .rtf in SciTe - the only special character was the Chr(0) at the end. After I ran the code, the resulting .rtf was only one byte longer than the original and would open with Wordpad.Then maybe you can print it using the Word Management print command in the beta - but to be honest, I don't have a printer installed on my system. It looks like you might have to convert the .rtf to .doc format to print it using that udf - you could use _WordDocOpen from the udf because the fouth parameter is for a format conversion. Then you would use _WordDocSave and then _WordDocPrint. Edited April 11, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
MHz Posted April 11, 2008 Share Posted April 11, 2008 (edited) Can you explain? That seems rather drastic, since I'm trying to build a production script for distribution. I've always shied away from building on anything other than the latest official release. Are there specific new features that would solve this right-justify problem? And is a new release planned soon -- so that I would only be on the beta for a short while?You do not need Beta AFAIK to complete your task. Production has _Word...() UDFs (even if you have Word) so see no use to make the project use Beta. Printers normallly print left to right so it is perhaps a printer setting needed to change to right to left. Edited April 11, 2008 by MHz Link to comment Share on other sites More sharing options...
DaleHohm Posted April 11, 2008 Share Posted April 11, 2008 Sheesh... don't make it so hard. He doesn't need the Beta and he doesn't need RTF. The following will create a 3 line file of text justified to a right margin of 80 characters. $line1 = StringFormat("%80s", "This is a Test") $line2 = StringFormat("%80s", "This is Right Justified") $line3 = StringFormat("%80s", "ABCDEF") FileWriteLine("C:\myfile.txt", $line1) FileWriteLine("C:\myfile.txt", $line2) FileWriteLine("C:\myfile.txt", $line3) Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
qwert Posted April 11, 2008 Author Share Posted April 11, 2008 (edited) StringFormat("%80s", "This is a Test")Dale, thanks for sticking with this and for showing the simple solution. My head was swimming a bit with the complexity of all the suggestions. I'll put the StringFormat and FileWriteLine inside a loop and my problem will be solved.The silver lining of all the other suggestions is that I now think I have a feel for what will be required if I need to carry things further -- like printing multiple columns on a page. But I'll save that for next year.Thanks again. Edited April 11, 2008 by qwert Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now