If statement bracket problem (?)

Advanced Macro Recorder/Editor.

Moderator: Pulover

ShadowNinja
Posts: 2
Joined: 08 Sep 2017, 11:27

If statement bracket problem (?)

08 Sep 2017, 13:47

Hello,

I am currently stuck on trying to figure out how the expression IF statement works in Pulover's Macro Creator v5.0.5. The script below is a simple test I made before I expand my idea into a bigger macro. What should happen with this script is the following: 1) Click on a certain cell in Excel, copy the cell (the content of the cell is the number 00065845). 2) That cells data is now on the clipboard; turn the current clipboard into a variable called CopiedData. 3) IF statement that evaluates if CopiedData = the number 00065845. If it does, pop up a message box that says "IT WORKS".

The problem here is that I cannot get this to work in PMC. When I export the macro to .ahk and remove the ( ) and { } from the IF statement, the macro works as intended and the pop up box shows up. There is definitely some kind of formatting issue I am missing but I have no idea what it is. I've tried CopiedData = 00065845, CopiedData = "00065845", %CopiedData% = 00065845, and %CopiedData% = "00065845" all to no avail. Here is a picture of the expression if statement window. I also tried the clipboard IF statement in the dropdown menu (see this picture) but couldn't get that to work either.

PMC version of macro with ( ) and { } in the IF statement; does not function as intended. Here is an image of the left command box

Code: Select all

WinActivate, Microsoft Excel - UOC_STUDENT_EXEMPT_1021051812.xlsx ahk_class XLMAIN
Sleep, 203
Click, 918, 221 Left, 1
Sleep, 93
Send, {Control Down}{c}{Control Up}
Sleep, 300
CopiedData := clipboard
Sleep, 300
If (CopiedData = 00065845)
{
    Sleep, 300
    MsgBox, 0, Box1, IT WORKS
    Sleep, 300
}
.ahk version that I edited by removing the ( ) and { } from the IF statement; works as intended

Code: Select all

WinActivate, Microsoft Excel - UOC_STUDENT_EXEMPT_1021051812.xlsx ahk_class XLMAIN
Sleep, 203
Click, 918, 221 Left, 1
Sleep, 93
Send, {Control Down}{c}{Control Up}
Sleep, 300
CopiedData := clipboard
Sleep, 300
If CopiedData = 00065845

    Sleep, 300
    MsgBox, 0, Box1, IT WORKS
    Sleep, 300
Thank you for any help and advice you can give me.
Drizzy

Re: If statement bracket problem (?)

09 Sep 2017, 21:40

I can confirm this is a bug, hopefully it will get fixed soon
ShadowNinja
Posts: 2
Joined: 08 Sep 2017, 11:27

Re: If statement bracket problem (?)

11 Sep 2017, 09:19

Drizzy wrote:I can confirm this is a bug, hopefully it will get fixed soon
Thank you for letting me know! That definitely explains why I couldn't get it to work. Do you know if Pulover knows about the bug?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: If statement bracket problem (?)

11 Sep 2017, 10:42

I can NOT confirm there is a bug in PMC, I can confirm that removing {} is definitely the wrong move.
Removing the () is somewhat iffy, meaning: it does not matter in your posted case whether you keep them or not, both versions would work if Excel would give you what you expected (which it does not), but for the sake of avoiding future confusion, it is generally recommended, that you only use the version WITH the parentheses.

I suggest you check carefully the following:
1 - Put a different number into your Excel cell, such as 123456 or anything you like.
2 - Run your first script.
3 - Run your edited script.

You will see: your edited script will INCORRECTLY show the MsgBox.
I therefore say: there is no bug with PMC. The bug in your code is caused by something else. (PMC might very well have a bug, I don't know, but it is not causing your error.)
Put back the () and the {}, then start again to look where the problem lies.

Next hint: use this If (CopiedData = "00065845`n"), do you get the desired result?
I can not test exactly, my Excel is an older version, it does not support *.xlsx, sorry.

Return to “Pulovers Macro Creator”

Who is online

Users browsing this forum: No registered users and 20 guests