Array behaving differently than variable? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
damascus_the_white
Posts: 11
Joined: 18 Feb 2022, 11:32

Array behaving differently than variable?

Post by damascus_the_white » 08 Dec 2022, 14:45

Hello all,

I'm having an issue where an array isn't behaving the same way as a variable and I'm not sure what I'm missing (probably an understanding of how Arrays fundamentally work in AHK).

In my examples I'm driving Excel via COM and using the .CopyPicture() function to copy a picture of a range of cells. I then paste that into a PowerPoint slide.

This code works:

Code: Select all

xl.Sheets("Sheet1").Range("A1:C10").CopyPicture(1, 2)
pic := ClipboardAll
; Later in the code
Clipboard := pic
activeSlide.Shapes.PasteSpecial()
This code does not work:

Code: Select all

pictures := []
xl.Sheets("Sheet1").Range("A1:C10").CopyPicture(1, 2)
pic := ClipboardAll
pictures.Push(pic)

; Later in the code
pic = pictures[0]
Clipboard := pic
activeSlide.Shapes.PasteSpecial()
What gets pasted in the second example is a character that looks as if it is trying to represent a binary element (a little square looking empty icon).

Am I missing something obvious with how Arrays work in AHK? Reading through the Object-based Arrays section of the documentation seems to imply this should work?

damascus_the_white
Posts: 11
Joined: 18 Feb 2022, 11:32

Re: Array behaving differently than variable?

Post by damascus_the_white » 08 Dec 2022, 16:03

damascus_the_white wrote:
08 Dec 2022, 14:45

Code: Select all

pic = pictures[0]
There is a typo in my post (but not in my actual code). This should read:

Code: Select all

pic := pictures[0]

[Mod edit: Fixed tags that put the whole post in a code box and broke the quote.]

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Array behaving differently than variable?  Topic is solved

Post by swagfag » 08 Dec 2022, 16:06

ah i see uve comitted the cardinal sin when writing v1 code of assuming. assuming things should work in certain ways. then u dared sin further by not trudging through the docs, committing pagesworth of gotchas to memory. truly an affront to the v1 coding gods
ClipboardAll#LOL wrote: Further limitations apply:
  • ...
  • When used in ways other than those described above, binary clipboard data is usually interpreted as text and truncated at the first null character, which is typically at the beginning of the data. For instance, this occurs when one attempts to return the data from a function or assign it to a property or array element.
"solution": dump the clipboard to disk; keep instead an array of filenames; read in the clipboard dumps; (optionally delete the files/names from the array); paste special
real solution: use v2

damascus_the_white
Posts: 11
Joined: 18 Feb 2022, 11:32

Re: Array behaving differently than variable?

Post by damascus_the_white » 08 Dec 2022, 16:11

swagfag wrote:
08 Dec 2022, 16:06
"solution": dump the clipboard to disk; keep instead an array of filenames; read in the clipboard dumps; (optionally delete the files/names from the array); paste special
real solution: use v2
wow.. that is. something. Looks like v2 is getting another look! thanks!

Post Reply

Return to “Ask for Help (v1)”