Jump to content

_ClipPutFile() and ClipPut() Issues, 2 weird bugs


Recommended Posts

Hi

I am currently working on a tool, with which you can paste some pictures and texts via a gui Buttons. I have two problems that I just can't figure out how to solve, both of them seem to have to do with the _ClipPutFile() function.

Problem 1:

If I run the script

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Sleep(3000)
$signaturepath = @ScriptDir & "\" & "a" & ".jpg"
$menutext = "fischers fritz fischt frische fische"

Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")

Sleep(300)
ClipPut($menutext)
Send("^v")

Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")

Sleep(300)
ClipPut($menutext)
Send("^v")

Sleep(300)
ClipPut($menutext)
Send("^v")

in a Word file, I only get the "fischers fritz fischt frische fische" once. It should have been pasted 3 times in total.

Problem 2:

After pasting two different images with the gui and two texts (Image, Text, Image, Text), I get a weird black box in word. See attached File Error2.docx. Does anybody know why this happens and what this is? If I paste more text, the black box just gets bigger.

The two functions used to get the result seen in Error2.docx are:

Func WriteButtonText() ; WriteButtonText
    Dim $menutext = STRING(GUICtrlRead(@GUI_CtrlId, 1)) ; return the text of the menu item
    GUISetState(@SW_HIDE)
    Sleep(300)
    ClipPut($menutext)
    Send("^v")
EndFunc   ;==>RE1

 

Func InsertSignature()
    Dim $menutext = GUICtrlRead(@GUI_CtrlId, 1) ; return the text of the menu item
    GUISetState(@SW_HIDE)

    $signaturepath = @ScriptDir & "\Images\signatures\" & $menutext & ".jpg"
    Sleep(300)
    _ClipPutFile($signaturepath)
    Send("^v")
EndFunc

Thank you!

a.jpg

Error2.docx

pastetowordbug.au3

Error1.docx

Link to comment
Share on other sites

Personally I would use Word UDF for this however with regards to the issues:

Error1: Try emptying the clipboard between pasting for example:

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Sleep(3000)
$signaturepath = @ScriptDir & "\" & "a" & ".jpg"
$menutext = "fischers fritz fischt frische fische"

Sleep(300)
ClipPut("")
_ClipPutFile($signaturepath)
Send("^v")

Sleep(300)
ClipPut("")
ClipPut($menutext)
Send("^v")

Sleep(300)
ClipPut("")
_ClipPutFile($signaturepath)
Send("^v")

Sleep(300)
ClipPut("")
ClipPut($menutext)
Send("^v")

Sleep(300)
ClipPut("")
ClipPut($menutext)
Send("^v")

Error2: The black squares are actually words with a very very small font size and have black shading switched on so that it appears completely black.  The text reads:

"ten Dank für das angenehme Gespräch. Gerne sende ich Ihnen wie besprochen die Offerte für" 

Link to comment
Share on other sites

Thank you, Error 1 is fixed. I can not use the word udf as this needs to work outside of word.

I finally found a ways to reproduce Error 2: It is the full stop "." at the end of the string that causes it.

Full Stop and a space also gives the same result: ". "

However Full stop and double space ".  " is fine as well as full stop and a letter: ".a" for example.

Hence it didn't happen with the example posted. With the following script I always get those black boxes:

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Sleep(3000)
$signaturepath = @ScriptDir & "\" & "a" & ".jpg"
$menutext = "fischers fritz fischt frische fische."

Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")
Sleep(300)
ClipPut("")

Sleep(300)
ClipPut($menutext)
Send("^v")

Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")
Sleep(300)
ClipPut("")

Sleep(300)
ClipPut($menutext)
Send("^v")

Sleep(300)
ClipPut($menutext)
Send("^v")


$signaturepath = @ScriptDir & "\" & "b" & ".jpg"
$menutext = "fischers fritz fischt frische fische."

Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")
Sleep(300)
ClipPut("")

Sleep(300)
ClipPut($menutext)
Send("^v")

Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")
Sleep(300)
ClipPut("")

Sleep(300)
ClipPut($menutext)
Send("^v")

Sleep(300)
ClipPut($menutext)
Send("^v")

Which results in the attached picture. Any Idea what causes this? How to prevent this from happening?

Cheers

PS: This code results also in the black box:

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Sleep(3000)
$signaturepath = @ScriptDir & "\" & "a" & ".jpg"

Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")
Sleep(300)
ClipPut("")
Sleep(300)
Send("hello.",1)
Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")
Sleep(300)
ClipPut("")
Sleep(300)
Send("Second Hello",1)

However, the following code is fine:

#include <MsgBoxConstants.au3>
#include <Misc.au3>

Sleep(3000)
$signaturepath = @ScriptDir & "\" & "a" & ".jpg"

Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")
Sleep(300)
ClipPut("")
Sleep(300)
Send("hello."&"  ",1)
Sleep(300)
_ClipPutFile($signaturepath)
Send("^v")
Sleep(300)
ClipPut("")
Sleep(300)
Send("Second Hello",1)

 

2017-03-26 15_49_18-Document1 - Word.png

Edited by Spongioblast
Link to comment
Share on other sites

I think you just need to place delays between send and clipput and also clear clipboard.  You could use a function for example:

#include <MsgBoxConstants.au3>
#include <Misc.au3>

$signaturepath = @ScriptDir & "\" & "a" & ".jpg"

_SendClip($signaturepath, 300, 1)
_SendClip("hello")
_SendClip($signaturepath, 300, 1)
_SendClip("Second Hello")

Func _SendClip($sSendClip = "", $iSendDelay = 300, $iSendType = 0)
    ClipPut("")
    If $iSendType = 1 Then
        _ClipPutFile($sSendClip)
        $sSendClip = "^v"
    EndIf
    Sleep($iSendDelay)
    Send($sSendClip)
    Sleep($iSendDelay)
EndFunc

 

Link to comment
Share on other sites

I think the delays aren't the issue. You just need to add a full stop to the first Hello like this:

#include <MsgBoxConstants.au3>
#include <Misc.au3>

$signaturepath = @ScriptDir & "\" & "a" & ".jpg"

_SendClip($signaturepath, 3000, 1)
_SendClip("hello.")
_SendClip($signaturepath, 3000, 1)
_SendClip("Second Hello")

Func _SendClip($sSendClip = "", $iSendDelay = 300, $iSendType = 0)
    ClipPut("")
    If $iSendType = 1 Then
        _ClipPutFile($sSendClip)
        $sSendClip = "^v"
    EndIf
    Sleep($iSendDelay)
    Send($sSendClip)
    Sleep($iSendDelay)
EndFunc

And then you get the black bar instead of the Second Hello.

Cheers

Edited by Spongioblast
Link to comment
Share on other sites

I see what you mean, it appears that the full stop + binary image is being read as a Word format command. so <Image>hello<.Image>Second Hello, if you place a break after the full stop as you mentioned above like: "Hello. " or "Hello." & "{Enter}" the issue doesn't occur

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...