Gui button name length - not enough

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Snowy42
Posts: 42
Joined: 03 Jul 2017, 18:32

Gui button name length - not enough

16 Apr 2021, 00:41

I'm creating a small script that grabs information from another program as a CSV then processes the info and passes it out to a GUI so that we can make a work request at work.

The problem I'm having is that I have a text string for a "description" field, which can be up to 1000 characters long. I've got a subroutine linked to the text field that copies the text string to the clipboard. However it only seems to copy the first 50-60 characters of the string.

Code: Select all

Gui, Add, text, x180 y%ypos% w350 gCopyDesc, % description[A_Index] ; gui creation placed in a loop so multiple items can be collected
 ; for the purpose of this example, the '% description[A_Index]' could just be replaced with a long line of gibberish
 
 ; subrouting for gCopyDesc as follows
 CopyDesc:
	clipboard := A_GuiControl
	msgbox Copied to clipboard.
return

How can I make this capture the entire string, rather than just the first 50-60 letters?

Thanks
Snowy42
Posts: 42
Joined: 03 Jul 2017, 18:32

Re: Gui button name length - not enough

16 Apr 2021, 00:50

Figured it out.... in case anyone wants to know.

I found this in the syntax for A_GuiControl:
The name of the variable associated with the GUI control that launched the current thread. If that control lacks an associated variable, A_GuiControl instead contains the first 63 characters of the control's text/caption
So, I instead used a variable. So the line to create the description field was then:

Code: Select all

Gui, Add, text, x180 y%ypos% w350 gCopyDesc vDsc%A_Index%, % description[A_Index]
Dsc%A_Index% := description[A_Index]
This meant that the A_GuiControl had the variable name (Dsc1,Dsc2,Dsc3,etc.) stored in it.

So then when I needed to grab that information on the clipboard I just used this:

Code: Select all

clipboard := %A_GuiControl% ; instead of doing it without the %'s
And hey presto! It works!
just me
Posts: 9449
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Gui button name length - not enough

16 Apr 2021, 09:29

More common ways:

Code: Select all

#NoEnv
Description := ["Hello world, this is my description!"]
ypos := 10
; gui creation placed in a loop so multiple items can be collected
Loop, 1
   Gui, Add, Text, x180 y%ypos% w350 gCopyDesc vDesc%A_Index%, % Description[A_Index] 
   ; for the purpose of this example, the '% description[A_Index]' could just be replaced with a long line of gibberish
Gui, Show
Return
GuiClose:
ExitApp
; subrouting for gCopyDesc as follows
CopyDesc:
   GuiControlGet, Desc, , %A_GuiControl%
   ; ClipBoard := Desc
   MsgBox, 0, Copied to clipboard:, %Desc%
return
or

Code: Select all

; subrouting for gCopyDesc as follows
CopyDesc:
   Index := SubStr(A_GuiControl, 5)
   Desc := Description[Index]
   ; ClipBoard := Desc
   MsgBox, 0, Copied to clipboard:, %Desc%
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: prototype_zero and 243 guests