Trouble Accessing Array Contents? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Posts: 6
Joined: 26 Jul 2020, 02:03

Trouble Accessing Array Contents?

09 Aug 2020, 01:51

I am having trouble accessing array contents I think.

Essentially, I am saving the already highlighted contents of a memo field with the clipboard.
Then, trying to use StrSplit to break up the memo into its individual words to be saved in an array.
Then, simply wanting to print the individual words from the array into an edit field, one word on each line.

Unfortunately it is not working. With the code below I get only the list of numbers in square brackets.

I am very new to this, so any assistance, information, tips, or etc. will be very welcome. Thanks! :)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^+x::  ; CTRL+Shift+X Hot Key

OriginalClipboardContents := ClipboardAll   ; Save the entire clipboard to the variable OriginalClipboardContents.

Clipboard := ""  ; Assigns the Clipboard contents as blank or empty to allow ClipWait to detect when the new text has been copied.

Gui, Add, Text,, Memo: ; These are the labels in the first column simply identifying the fields in the 2nd column to come.
Gui, Add, Text,, Split:

Gui, Add, Edit, w250 vMemo gMemo ym  ; Width, variable, label, and the ym option starts a new column of controls with this field.
Gui, Add, Edit, R5 w250 cSilver vSplit  ; Rows, width, color, variable.

SendInput ^c  ; CTRL+C Copies any highlighted text.
ClipWait  ; Wait for the clipboard to contain text.
Memo := Clipboard  ; Assigning the new contents the clipboard to the Memo variable.

GuiControl, , Memo, %Memo% ;  Displaying the new contents of the Memo variable in the Memo field.
GuiControl, , Split, Please enter the required information above. ;  This displays the instruction to enter the required information above.

Gui, Show  ; Tells the code to show the GUI just created.
return  ; End of auto-execute section. The script is idle until the user enters any information.

Memo:  ;  This will run when something has been entered in the Memo field.

Gui, Submit, nohide  ;  Save the input to each control's associated variable & prevents the window from being hidden.

; This checks to see if any information is missing.
If (Memo = "")
        return  ;  If any information is missing, this returns the code back to the auto-execute section to wait until the user enters more information. 

; This splits the Memo into an array of strings, split by spaces, removing commas, with max of 4 seperate strings and then the remainder of the Memo.
MemoWordArray := StrSplit(Memo, A_Space, ",", 5)

GuiControl, , Split, %MemoWordArray%[1] `n %MemoWordArray%[2] `n %MemoWordArray%[3] `n %MemoWordArray%[4] `n %MemoWordArray%[5] ;  This prints the 5 strings from the MemoWordArray, with 1 on each line.



Gui, Destroy
Clipboard := OriginalClipboardContents   ; Restore the original clipboard contents. Note the use of Clipboard, (not ClipboardAll).
OriginalClipboardContents := ""   ; Free the memory from the OriginalClipboardContents variable in case the clipboard was very large.

User avatar
Posts: 847
Joined: 29 Sep 2013, 19:01

Re: Trouble Accessing Array Contents?  Topic is solved

09 Aug 2020, 02:25


Code: Select all

GuiControl, , Split, % MemoWordArray[1] "`n" MemoWordArray[2] "`n" MemoWordArray[3] "`n" MemoWordArray[4] "`n" MemoWordArray[5]      ;  This prints the 5 strings from the MemoWordArray, with 1 on each line.
Posts: 6
Joined: 26 Jul 2020, 02:03

Re: Trouble Accessing Array Contents?

09 Aug 2020, 03:01

Thank you so much, flyingDman! :bravo:

I had tried different combinations of percent signs but I had not thought about how the `n needed quotes and so was getting errors and thought it was wrong.

Thanks so much!

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], scriptor2016, songdg, williams and 42 guests