AutoHotkey Community

It is currently May 27th, 2012, 3:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: June 8th, 2010, 11:31 am 
Offline

Joined: June 7th, 2010, 6:26 am
Posts: 60
If I make a control like this:
Code:
Gui, Add, Edit, r10 veditbox

Then each time I add text to it, I don't want it to overwrite whatever is already in there. I just want it appended to the end. How can I do that?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2010, 12:05 pm 
Hey!

I don't know if it's the best way to do it, but you can get the current text of the edit control with GuiControlGet and then append text to that with GuiControl.

Like this:
Code:
Gui, Add, Edit, vc_edit w300 h300, This is some text
Gui, Show,, Some Text (Press Ctrl+R)
return

^r:: ;Press Ctrl+R
GuiControlGet, c_text,,c_edit
Inputbox, c_append, Text to append to the edit control, Type something
GuiControl,, c_edit, %c_text%`n%c_append%
return

GuiClose:
exitapp


http://www.autohotkey.com/docs/commands/GuiControl.htm
http://www.autohotkey.com/docs/commands/GuiControlGet.htm


Report this post
Top
  
Reply with quote  
 Post subject: Re:
PostPosted: June 8th, 2010, 3:53 pm 
I started writing this function to gain a little more access over inserting lines of texts into an edit control, and then I realized that hugov's TF library already offers the solution, but I finished it anyway. It's similar to TF_InsertLine/TF_ReplaceLine/TF_InsertPrefix/TF_insertSuffixx in functionality, only it's not as advanced as those.

It offers you an option to insert text before/after/replace a line of text, or N lines before/after the whole text.

I benchmarked TF_InsertLine and my function with a simple line inserting operation - if only to justify the time spent on coding it ;) - and the results show (as it's mentioned in the TF.ahk documentation) that the tf function's a bit slower with short texts, and faster with large texts. At 6MB and ca. 17000 lines of text the benchmark results were roughly the same, after that the tf function was clearly faster.

Anyway, I suggest you use the related TF functions to do serious stuff, as they're better thought through, more robust, and offer a lot more functionality, but if you feel like giving a shot to mine, go right ahead.

InsertToText.ahk
Code:
InsertToText(InputText,InsertText,InsertMode,RowNumber=0){
;// Error check
if (!InputText || (!Instr(InsertMode,"text") && !RowNumber) || !InsertMode) ;blank input, missing rownumber, missing insertmode
return 0
if RowNumber is not integer ;invalid rownumber
return 0
if InsertMode not in before,after,replace,before text,after text ;invalid insertmode
return 0
if !InsertText ;nothing to insert
return InputText
;// Insert before/after text
if InStr(InsertMode,"text") {
   if RowNumber
      Loop, % RowNumber
         LineFeed .= "`n"
   OutputText := InStr(InsertMode,"before") ? InsertText "`n" LineFeed "" InputText : InputText "`n" LineFeed "" InsertText
}
;// Insert before/after/replace line
else
   Loop, Parse, InputText, `n
   {
      if (a_index=1)
         LineFeed := ""
      else
         LineFeed := "`n"
      if (a_index=RowNumber)
         if (InsertMode="before")
            Outputtext .= LineFeed InsertText "`n" A_LoopField
         else if (InsertMode="after")
            OutputText .= LineFeed A_LoopField "`n" InsertText
         else
            OutputText .= LineFeed InsertText
      else
         OutputText .= LineFeed A_Loopfield
   }   
return OutputText
}


Parameters:
Code:
InputText - The input text to manipulate.

InsertText - The text to insert to InputText.

InsertMode - Specify:
 * "before" or "after" to insert a line of text, before/after RowNumber
 * "replace" to replace the RowNumber-th line
 * "before text" or "after text" to insert InsertText RowNumber Lines before/after the whole InputText.

RowNumber - Use it as described above, you can leave it blank if you use "before text" or "after text" as InsertMode:
In this case InsertText will be inserted right before/after InputText.


Examples:
Code:
a_list=
(
item1
item2
item3
item4
)

MsgBox, % InsertToText(a_list,"new_item","before",2)
MsgBox, % InsertToText(a_list,"new_item","after",2)
MsgBox, % InsertToText(a_list,"new_item","replace",2)
MsgBox, % InsertToText(a_list,"new_item","before text")
MsgBox, % InsertToText(a_list,"new_item","after text")
MsgBox, % InsertToText(a_list,"new_item","before text",10)
MsgBox, % InsertToText(a_list,"new_item","after text",10)


HugoV's Textfile & String Library
http://www.autohotkey.com/forum/viewtopic.php?t=46195

Cheers

gahks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2010, 3:59 pm 
Offline

Joined: January 10th, 2009, 6:40 pm
Posts: 32
And that was me btw. Freakin forum logged me out again. :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2010, 4:11 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Also look at the Edit library by jballi
http://www.autohotkey.com/forum/topic55062.html

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2010, 4:43 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Control, EditPaste

Note: I suggest you try IRC for real-time help: 17 questions in 5 hours is excessive.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2010, 3:08 am 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1713
Location: Somewhere near you
jaco0646 wrote:
17 questions in 5 hours
Image

You should chat at the IRC with tidbit, elesar, polyethene, and even robokins..

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2010, 3:12 am 
Offline

Joined: June 28th, 2007, 1:08 am
Posts: 662
tomoe_uehara wrote:
You should chat at the IRC with tidbit, elesar, polyethene, and even robokins..


:oops: Aww, I feel special :D

You should be on that list too, you're not too shabby at this code stuff.

But yes, IRC is the way to go for quick answers to multiple questions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2010, 3:24 am 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
Me???!Image
And yes, you forgot [tomoe_uehara, infoG, Temp01, BigVent, everyone else] on the list.
word of advice: careful what you ask me :twisted:
not reading through all the posts, so maybe this will help:
Code:
gui, submit, nohide
editbox.="`nNew text in the editbox!"
guicontrol, , editbox, %editbox%

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
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: rbrtryn, Yahoo [Bot] and 13 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