Solved

AutoHotKey vs Pulover's Macro Creator syntax

Posted on 2016-09-30
25
42 Views
Last Modified: 2016-10-23
So I have been using Pulover's Macro Creator to create a script but cannot create a new variable like this.

AptNum%A_Index% := Clipboard

Obviously I can type the code but I cannot create this in Pulover's Macro Creator.

See the screen shot.
Image-5.jpg
0
Comment
Question by:beatified
  • 13
  • 12
25 Comments
 
LVL 51

Assisted Solution

by:Joe Winograd, EE MVE
Joe Winograd, EE MVE earned 500 total points (awarded by participants)
ID: 41824115
As you know from our last thread together, I've been using AutoHotkey for a long time. However, I've never used Pulover's Macro Creator, although it has a good reputation in the AutoHotkey community.

Why are you using it? Why not write your own scripts?

I modified the script from our last question to use A_Index, AptNum, and Clipboard. Here it is:

Loop
{
  AptNum%A_Index%:=Clipboard
  CurrentVar:=AptNum%A_Index%
  Msgbox,4100,Variable AptNum%A_Index%,Current clipboard contents:`n%CurrentVar%`n`nCopy something else to clipboard and hit Yes`n(or hit No to exit)
  IfMsgBox,No
    ExitApp
  Continue
}

Open in new window

As you can see, it has this assignment statement:

AptNum%A_Index%:=Clipboard

Run it — you'll see that it works perfectly! If Pulover's Macro Creator is not working on it, the problem is with Pulover's Macro Creator, not AutoHotkey.

Btw, what is the value of A_Index when Pulover barfs on AptNum%A_Index%? Regards, Joe
0
 
LVL 2

Author Comment

by:beatified
ID: 41824135
Well the reason I'm not making my own scripts from scratch is that I have a much harder time with AHK. It just requires a lot of prior knowledge or at least constant referring back to the documentation to make get at the stuff I want to accomplish.

I actually started with AHK but found Pulover's Macro Creator and really like the simplicity it offers. I know its probably better for me to be creating my own scripts from scratch but I'm just in kind of a time crunch.

Maybe what I'll do is use Pulover's Macro Creator as much as I can then export to AHK and fix the stuff that should be working but isn't. Honestly there probably isn't a whole lot that is broken. So I dont think that should be too hard.

Thanks for the help again Joe.

Stuart
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 41824152
> Maybe what I'll do is use Pulover's Macro Creator as much as I can then export to AHK and fix the stuff that should be working but isn't.

Good idea! I know nothing about Pulover's Macro Creator, but if you post the AutoHotkey code, I'll be happy to help. Regards, Joe
0
 
LVL 2

Author Comment

by:beatified
ID: 41824156
Again Thanks so much for your help It is really appreciated. I'll work on it a little and see what happens but I will leave the question open for now but. I will reward you the points for sure even if I don't need any further help.

By the way I am emailing Pulover to inform him of the problem as I'm sure its something he would like to know.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 41824165
> I will reward you the points for sure even if I don't need any further help.

I'm not worried about the points.

> I am emailing Pulover to inform him of the problem

Another good idea! Let me know what he says — I'm very interested.
0
 
LVL 51

Assisted Solution

by:Joe Winograd, EE MVE
Joe Winograd, EE MVE earned 500 total points (awarded by participants)
ID: 41824305
Btw, a comment about the whole concept of a variable like Var%Index%. It is known as a pseudo-array, because you can think of it as an array where the array name is Var and the array element is Index. This used to be the only way to implement the notion of an array in AutoHotkey, but now it has robust support for actual arrays (more generally, Objects), both simple arrays and associative arrays. Maybe Pulover doesn't like pseudo-arrays, in which case you may want to switch to using an actual array. Here's what the script above would look like using an actual array:

AptNum:=Object()
Loop
{
  AptNum[A_Index]:=Clipboard
  CurrentVar:=AptNum[A_Index]
  MsgBox,4100,Element number %A_Index%,Current clipboard contents:`n%CurrentVar%`n`nCopy something else to clipboard and hit Yes`n(or hit No to exit)
  IfMsgBox,No
    ExitApp
  Continue
}

Open in new window


Regards, Joe
0
 
LVL 2

Author Comment

by:beatified
ID: 41824311
Ok I'm having a problem with the first copy and assign variable.

If you run it you will see what I mean.
Pay special second line of the msgbox. It seems to be applying both what was in the clipboard before the script was run and somehow its applying Cell B:29 clipboard contents

You must open the excel file before you run the script.

BTW I am using Excel 2016 not sure everything will work correctly on a different version.

I tried correcting this but cant figure it out.
DOS-Test.ahk
9-1-2016-Deposits.xlsx
0
 
LVL 2

Author Comment

by:beatified
ID: 41824314
BTW if you tell it line 2 and 28 records it should process everything.

It looks like its messing up the first line and last line.

And now that I look at it it seems its missing a date on 1040-C maybe thats a timing issue?
Image-6.jpg
0
 
LVL 2

Author Comment

by:beatified
ID: 41824319
Ok found the issue with 1040-C it was a typo.
0
 
LVL 2

Author Comment

by:beatified
ID: 41824321
Oh and the deposit number is the sheet name. In this case 14698.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 41824322
Stuart,
I'm going out to dinner now with my family. Will look at this later tonight or tomorrow. But in the meantime, describe for me what you are trying to achieve (not how). It may be a lot easier to write a script from scratch than to fix up what Pulover generates, but to do that, detailed specifications are necessary. Regards, Joe
0
 
LVL 2

Author Comment

by:beatified
ID: 41824338
Yeah of course please go to dinner.

But at this stage all I am trying to do is create variables for each cell except in column H.

The overall goal is automated data entry essentially.

My dad is using an obsolete and ancient database program for DOS and WP5.1 for DOS in order to track payments and amount owed.

Not only is it obsolete but also not normalized at all and the math is being done in WP not in DBASE.

Because it's not normalized and data entry is done in both WP and DBASE and is redundant I am trying to get the data needed into Excel then use that to enter the data automatically into his current system.

This is a short term fix so that it will simply take an hours worth of work and cut it down to a few minutes.

The goal eventually is to migrate to a Access DB.

My Dad has pretty severe pain in his eyes and is seeing horribly at this point so everything is getting much harder than it ever has been for him. He is very reluctant to change the way he does things so I am trying to at least make it easier at this point then move to Access as a longer term goal.

Seriously thank you so much for your knowledge and expertise so many people on here are only willing to do the bare minimum and you have not been that way at all. It is highly appreciated.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 41824401
Back from dinner.

> If you run it you will see what I mean.

I opened the spreadsheet (in Excel 2016), ran the script, and answered the three prompts with:

14698
2
28

Nothing happened. I saw no mouse movement and the spreadsheet was not changed in any way — I closed it and there was no "Want to save your changes" warning.

> It seems to be applying both what was in the clipboard before the script was run

That means you didn't clear the contents of the clipboard at the start of the script, i.e.:

Clipboard:=""

> It looks like its messing up the first line and last line.

As I said, it doesn't do a thing here.

> But at this stage all I am trying to do is create variables for each cell except in column H.

Is that not working? What variables are not being created?

> The overall goal is automated data entry essentially.

I'd like to understand that better.

Where is the original data?

By "data entry" do you mean from the original data source into the spreadsheet?

How does the spreadsheet get created?

Btw, that code is really hard to read. Regards, Joe
0
 
LVL 2

Author Comment

by:beatified
ID: 41824403
OK so it's not supposed to do anything other than copy the text and save create the variables with the copied text.

Did it create the Msgbox?
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 41824409
> Did it create the Msgbox?

No. Eventually I exit it from the system tray icon.
0
 
LVL 2

Author Comment

by:beatified
ID: 41824413
Okay after it is done it should create a message box.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 41824416
> Okay after it is done it should create a message box.

How long should it run?
0
 
LVL 2

Author Comment

by:beatified
ID: 41824417
It should do it immediately after it finishes with column I.
0
 
LVL 2

Author Comment

by:beatified
ID: 41824419
The message box is only there to confirm that everything is working correctly
0
 
LVL 51

Assisted Solution

by:Joe Winograd, EE MVE
Joe Winograd, EE MVE earned 500 total points (awarded by participants)
ID: 41824433
Insidious bug! EE's fault! When you upload files to EE, it doesn't like spaces in file names, so it replaces them with hyphens. So when I downloaded your spreadsheet, its name became:

9-1-2016-Deposits.xlsx

instead of:

9-1-2016 Deposits.xlsx

So the WinActivate command was never getting a match — script was hanging there forever.

I fixed that and now it runs and I get the MsgBox at the end. At a quick glance, it seems that the first line in the MsgBox is the last line in the spreadsheet (but has the wrong Number — 1044-54 instead of 1054). I'll see if I can find a problem, but, imo, this is not the way to write such a script.

Update: I started testing this, put in a few debugging MsgBox commands, and then it changed focus to my file manager and scared the dickens out of me — started highlighing a whole bunch of folders and I was worried about what it might do with all those Send commands — could have been really ugly. I don't think I lost any folders or files (not sure, though), but I'm not comfortable testing it anymore with that style of macro on a prod machine — all those Send and ControlClick commands (maybe later in a sandbox). There's a way to do this correctly and that's not it. If you want to stick with this approach, put in some well-placed MsgBox commands to see where the assignments are going wrong. If I figure out anything in a sandbox later, I'll let you know.

I'm still not understanding the end game here. After you get all the variables created properly in your AHK script, then what? Btw, how does the spreadsheet get created? Where did the data reside when the spreadsheet was created? Regards, Joe
0
 
LVL 2

Author Comment

by:beatified
ID: 41824797
Sorry about the scare. Is there a better way to do this?

I considered just calling each cell the same way I select the first Cell and not doing the tab and arrow thing. In other words select B:2 B :3 and so on.

So after the variables get created the idea is simple just use send to send the variables to DOS programs.
0
 
LVL 51

Accepted Solution

by:
Joe Winograd, EE MVE earned 500 total points (awarded by participants)
ID: 41824810
> Is there a better way to do this?

Yes, much better! Stop the whole "ControlClick/Send/Sleep" approach. Write a "real" AutoHotkey program. You seem to be knowledgeable about normalized data and Access databases, and you made an attempt to modify the Pulover code, so I presume you have at least some programming background. Here's a starting point for a real program:

#Warn,UseUnsetLocal
#NoEnv
#SingleInstance Force
SetBatchLines,-1

SourceFile:="c:\temp\9-1-2016 Deposits.xlsx"
NumberColumns:=9
NumberRows:=29

Output:=""
ColumnLetters:=["A","B","C","D","E","F","G","H","I"]
oWorkbook:=ComObjGet(SourceFile)
ExcelCells:=Object()
Loop,%NumberRows%
{
  If (A_Index=1)
    Continue ; ignore first row
  CurrentRow:=A_Index
  Loop,%NumberColumns%
  {
    If (A_Index=1 or A_Index=8)
      Continue ; ignore columns A and H
    If (A_Index=6)
      SetFormat,Float,6.2
    If (A_Index=7 or A_Index=9)
      SetFormat,Float,6.0
    CurrentColumn:=ColumnLetters[A_Index]
    CurrentCell:=CurrentColumn . CurrentRow
    ExcelCells[CurrentColumn,CurrentRow]:=oWorkbook.Worksheets(1).Range(CurrentCell).Value
    If (A_Index=2)
      Output:=Output . "10" . ExcelCells[CurrentColumn,CurrentRow] . "-"
    Else
      Output:=Output . ExcelCells[CurrentColumn,CurrentRow] . " - "
    If (A_Index=9)
      StringTrimRight,Output,Output,3
  }
  Output:=Output . "`n"
}
MsgBox,4096,Values in Excel,%Output%
ExitApp

Open in new window

Here's the MsgBox output from running that program on your spreadsheet:

Excel COM script output
The script needs additional work, but it should get you headed in a much better direction. Btw, the spreadsheet should not be open when you run it.

> So after the variables get created the idea is simple just use send to send the variables to DOS programs.

At that point I'm fine with using Send, if there's no better way to communicate with the old DOS programs (and there probably isn't).

You haven't answered my earlier questions of where the data resides when the spreadsheet is created — in dBASE? WP5.1? And how it gets created — manually? export/Save As? a program you wrote? I'd like to understand that. Regards, Joe
0
 
LVL 2

Author Comment

by:beatified
ID: 41827316
Thanks so much for the script and all the hlep. The data is manually entered.

So this is the flow at the moment.
1. Check is received
2. Info for the check is handwritten onto a piece of paper.
3. Receipt is hand written.
4. Check info is entered into WP 5.1.
5. Macro is run that does the math and calculates the balance.
6. DBase is opened and there are about 4 steps that are all redundant and not even close to normilized in completely different DB files. All these steps are just entering the same information as what is on the hand written version.

My future version of this.
1. Enter the check info into Excel (only as a means to create a master record of all checks)
2. Hand write the receipt (my dad just insists on this)
3. Have the script store all the info needed as variables and then enter all that info into WP 5.1 and in all needed places in DBase.
4. Done.

So after the initial data entry into Excel which will be the only time consuming part of all this. There will be no other work involved other than running the script. This takes me hours and hours each day to do. And my dad can hardly see and is in pretty bad pain most of the day and he tends to insist on doing this even though I'm capable of doing it. I guess when I started doing it the first time I quickly understood that this could be automated and made much easier.

Also when a mistake is made in DBase it is extremely dificult to fix. And the way that I see it is as long as the data in Excel is accurate and the script runs properly then the chance for error is zero. I would rather take a few minutes and assure myself that the data in Excel is correct in the long run. I stand a much better chance at accuracy that way.

I fully understand this is a bandage to a gaping wound but none the less it will relieve a ton of stress and give me time to make the full blown Access Database.

So this idea is just to make life easier at the moment and honestly its a learning experience for me. Although I understand the concepts involved in databases and scripts putting them into practice is much harder for me. Its more of a syntax issue for me and understanding how to do things efficiently not just do them. Also how to do things in order to minimize the chance for error in the script.
0
 
LVL 51

Assisted Solution

by:Joe Winograd, EE MVE
Joe Winograd, EE MVE earned 500 total points (awarded by participants)
ID: 41827509
Hi Stuart,
Thanks for the explanation — very helpful! Two things caught my eye: "as long as...the script runs properly" and "how to do things in order to minimize the chance for error in the script". That's why you should stop the ControlClick/Send/Sleep approach for accessing the data in Excel, which can be error-prone, especially the Sleep component — as you were troubleshooting the errors in the script, you mentioned, "maybe thats a timing issue". And if your dad tries to do something else on the computer while that script is running, it can really go haywire on him.

The script I wrote for you gets all of the data out of Excel reliably. At this point, is there anything else you'd like from me? Regards, Joe
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 41855857
Selected posts provide a solution.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now