I have created a GUI in AHK and it works well now. I am processing multiple records and would like to be able to track the place that I am on. My code loops through each record and does some actions before moving on to the next one. While this is happening the GUI window is shown. Also I am writing this in AHK then using the conversion tool and creating an .exe with it. I am developing this tool to be distributed as a stand alone EXE that one can install/save and then run when they want to. Below is a screen shot of the tool and the code to load in the names.
Gui, PasteGUI:Add, Text,, Please add the Names that you want to Process.
Counter := 0
Loop, parse, Clipboard, `n, `r
{
x%A_Index% := A_LoopField
Counter++
}
Counter--
Loop, %Counter% ; Dynamic List length
Gui PasteGUI:Add, Edit, vButton%A_Index%, % x%A_Index%
Gui PasteGUI:Add, Button, x200 y270 w88 h26 vButton02 gGoCont Default, Continue
Gui PasteGUI:Add, Button, x290 y270 w88 h26 vButton03 gGoQuit, Cancel
Gui, PasteGUI:Show
}
Return
GoCont:
{
Loop, %Counter%
{
CODE TO PROCESS MY EACH NAME
}
MsgBox Done!
Gui Destroy
}
Return
GoQuit:
Gui Destroy
Return
I want to add something so that when I am processing Jason it can be identified. Having an arrow that moves as I loop through the list would be nice. As I have depicted it below,I drew it on in paint. Otherwise if I could turn the past records a color that would work too. So for the below example the names "Chris" & "Ben" would be highlighted in a color or the boxes would be somehow identified as different. I am not sure how to do either so it would be great to learn both if possible. Lastly, whatever method is described I need to be able to convert it to an .exe with Ahk2Exe and then be able to run the .exe and not have a need to have any further files or other references in the program that would not work. This is interned to be run on a standard Windows computer so if there are some default images that can be accessed that might be useful too.
Okay so Ive worked out how to do this with PGilm's method of checkboxes. You could also possibly do this with a table of some sort. But the code below looks to be working for me.
Also I wanted to let you know I changed the var x to cliparray so it is easier to read.
Gui, Add, Text,section, Please add the Names that you want to Process.
Counter := 0
Loop, parse, Clipboard, `n, `r
{
cliparray%A_Index% := A_LoopField
Counter++
}
Counter--
Loop, %Counter% {
; Dynamic List length
Gui, Add, Checkbox, xs vCheckBox%A_Index%
Gui Add, Edit, yp+1 xs+30 vTextbox%A_Index%, % cliparray%A_Index%
}
Gui Add, Button, x200 y270 w88 h26 gGoCont vButton02 Default, Continue
Gui Add, Button, x290 y270 w88 h26 vButton03 gGoQuit, Cancel
Gui, Show
Return
GoCont:
;needed to get the variables from the edits and check box, else the varibles dont exist See below for more information.
Gui, Submit, NoHide
msgbox, Go..
Loop, %Counter%
{
line=Textbox%A_Index%
GuiControl,, CheckBox%A_Index%, 1
backone:=A_Index-1
GuiControl,, CheckBox%backone%, 0
Msgbox % "variable " line " contains: " Textbox%A_Index%
}
MsgBox Done!
Return
GoQuit:
Gui Destroy
Return
;Used to debug to see list of all variables. Super helpful :D
F7::
ListVars
return
Some logic to take note of would be on the lines that add the edits and checkbox's. I used the Section logic of Gui positioning to make the edit and check on the same line. In this code the section element is set in the first Gui, Add, for the text section. And thus carries down to the other gui elements. Section AHK Documentation
Gui, Add, Checkbox, xs vCheckBox%A_Index%
Gui Add, Edit, yp+1 xs+30 vTextbox%A_Index%, % cliparray%A_Index%
The next part to take a closer look at is in the GoCont function. I am using the index of the loop to check the CheckBox%A_Index% checkbox so that the current line turns on. I also turn off the last index's check box with the GuiControl,, CheckBox%backone%, 0 line. This give the effect of the check box moving through list as you process text with in each element.
One last line to mention is the Gui, Submit, NoHide. Without this you will be missing the variables created for each checkbox and edit. This will create and fill the variables with the data from each gui element. Gui, Submit AHK Documentation
Related
I need to find the control's name to which its tooltip is linked.
I'm asking this because I need to control click within TeamCenter 10, but the control names keep changing just as you click on any of them. This makes it difficult to keep my code running smoothly when I need to repeat tasks.
If there is a better way of doing this (in Autohotkey), please let me know.
You can try this (Replace title of TeamCenter 10 with the exact title of the TeamCenter window as shown in Window Spy):
F1::
; Retrieve the control name for each control in a window:
WinGet, List, ControlList, title of TeamCenter 10
; Examine the individual control names one by one, using a parsing loop:
Loop, Parse, List, `n
{
If InStr(A_LoopField, "SWT_Window02") ; use only the part of the control name that is always shown in Window Spy
ControlClick, %A_LoopField%, title of TeamCenter 10
break
}
return
https://autohotkey.com/docs/commands/WinGet.htm#ControlList
I'm using Excel 2016 on my Mac (v10.11) and currently working on a table for the accounting of my company. It contains two sheets: On the first sheet I list up some costs and give them a projectnr. These costs get copied and pasted on the second sheet. The projectnrs get copied in a protected column, where I need to delete all duplicates. I want to automate this process. if you click on a button on the first page, the rest of the game will be done by itself.
For this, I wrote a VBA function like this:
Option Explicit
Sub Copy()
ThisWorkbook.Worksheets("FirstTable").Range("R21:R84").Copy
ThisWorkbook.Worksheets("SecondTable").Cells(3, 26).PasteSpecial xlPasteValues
ThisWorkbook.Worksheets("SecondTable").Activate
ThisWorkbook.Worksheets("SecondTable").Range("Z:Z").RemoveDuplicates Columns:=1, Header:=xlYes
ThisWorkbook.Worksheets("FirstTable").Activate
ActiveWorkbook.Save
Call Print
End Sub
The problem is that the method RemoveDuplicates does not work on mac! I've tested it on windows and everything works well. Does anyone know what the reason for this could be?
If I mark the column on my own and click on remove duplicates in the data tab, it works, but not with this macro.
I found the reason why it doesn't work:
On mac it pops up a dialog, which you need to confirm. If you don't hit the confirm button, the duplicates won't be removed. After I call the RemoveDuplicates function, I switch to the FirstTable by calling ThisWorkbook.Worksheets("FirstTable").Activate. The dialog disappears and the duplicates are not deleted.
On windows there is no dialog, thats why it works.
I am a newbie with AutoHotKey, and to this point I consider myself fortunate to have created a script to automate about 90% of the data entry in a window. I'm now trying to kick it up a notch and add a warning/caution GUI to my data entry script. I want to pause the running script and open a GUI that will alert me to look at what has already been entered, with one button to allow things to proceed if a particular entry looks OK, and another to dump out of both the GUI and the remainder of the script if the entry is incorrect.
Here's some code I came up with, mixed with some pseudocode to help show what I want to do.
(Previous data entry script executes to this point)
Stop the script
Gui, New
Gui, Add, Text, 'n Check Authorization Number to be sure it is A1234 (FY 15). ; Wraps text
Gui, Add, Button, Default, Continue
Gui, Add, Button, Quit
Gui, Show, IMPORTANT!
If Continue button is clicked
----Continue with script
If Abort button is clicked
----Close the GUI
----Exit the entire script
(Resume where I left off with rest of the data entry script)
I've read the AHK Help file and am stumped about how to make these buttons work, as well as how to properly return from the GUI back to the script if I hit continue, or quit the whole thing if I spot a problem. I can tweak things like the size of the GUI and the button placement; what's most important is getting the GUI code right. Can someone help with the code? (The last programming class I took was in 2003, so I have forgotten a whole lot!)
In your case, a GUI would be overkill. AHK (and many other languages at that) provide standard dialogs for simple user interaction called message boxes.
Message boxes in AHK can be displayed in two ways:
MsgBox, This is a simple message. Please click "OK".
MsgBox, 4, Attention, Here`, you can choose between "Yes" and "No".
In the second case, we declared an option which controls the buttons that are displayed. You can use IfMsgBox in order to detect what the user has clicked:
IfMsgBox, Yes
MsgBox, 4, Really?, Did you really mean "Yes"?
Putting these pieces together, we can ask the user to decide if they want to continue, without the need to create a GUI, in a few lines:
; Option "1" is "OK/Cancel"
MsgBox, 1, IMPORTANT!, Check Authorization Number to be sure it is A1234 (FY 15).
IfMsgBox, Cancel
{
ExitApp
}
; do stuff
This code addresses each of your other problems, too:
A message box halts the current thread until the user dismisses the dialog or it times out (if you specifically declared a timeout).
To completely stop the execution of our script, we use ExitApp.
I have the following script:
gosub, menucreate
Settimer, CheckRun, 1000
ExitSub:
ExitApp
return
Mess:
msgbox tada
return
menucreate:
Menu, TRAY, DeleteAll
Menu, TRAY, NoStandard
Menu, TRAY, Add, Exit , ExitSub
Menu, TRAY, Add, Message , Mess
return
CheckRun:
gosub ,menucreate
return
On occasions the menu Message works, but sometimes not.
Every few starts of this program it shows the message, and it keeps working if I reload.
But if I restart it might not working (or might ... I couldn't figure out any pattern)
To me it seems like you fail to end the Auto-execute section.
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
So try and put a return after your settimer and see if that helps
OK, in mean time I found out, but till now hadn't time to add this here (and kinda forgot).
The thing is: If the menu gets redrawn every second it will only cause an action until it gets redrawn.
So if you have pulled it up and the redraw happens before you click on a item nothing happens.
This thing here was just a test script to find out why the actual one has stopped working.
In that one I have included a test if actually something has changed and only then the menu get redrawn ... and voila it works.
I have recently been asked if I could make a macro in Excel VBA that will allow a user to type in two numbers and have it automatically drop to the next row. The purpose of this is so they can type in grades for a test two numbers at a time without pressing enter since they aren't great at typing.
When I first heard this he mentioned it was Visual Basic, so I figured I'd just use a TextChanging or TextChanged event in the cell range and have it work off that. However, I haven't been able to find any such event or anything resembling it in the documentation thus far. The first thing that I came across was Workbook_Change, but that only changes after you press enter which is useless to me. Someone else mentioned there is such an event, but couldn't name it directly and I haven't been able to find what they were talking about.
If anyone has any information on if such an event exists or is possible I'd love to know.
The Excel version is 2007 as far as I'm aware.
This, in my opinion, requires a non-programming solution. I absolutely sympathize - it is tough to watch people get old - but you have to draw the line somewhere - for their sake and yours. The enter key is the most basic part of a computer. You could probably write a macro that would automatically hit enter on every even(or odd depending) keystroke in excel - but you're going to run into other problems like not being able to use delete normally. And what if you do want to put a string of text in a cell(like the student's name)? Perhaps it is time to find a non-programming solution. By that I mean someone should have a candid conversation with him about how he wants to solve the problem. Personally, I would offer to type the numbers in for him, as I am accustomed to the number pad - but it is probably better to be more direct and start to discuss retirement.
See this discussion about the limitations of cell edit mode in excel:
http://www.mrexcel.com/forum/excel-questions/524860-call-macro-every-keystroke.html
If you're really heart-set on a programming solution, I would recommend some kind of keystroke logging add-in.
Good Luck.
You could use the Worksheet_SelectionChange event. It is triggered without enter, but it would be triggered a lot.
You could however also create a special user-form for typing in the data, but this might be more work than necessary.
The main problem with using my suggested event is, you will need it as trigger and trigger it yourself, when selecting the next row, so disable event handling before changing the selection.
Edit:
This is a quick solution (paste this into the vba-code of the desired worksheet):
Private Const clngColumnRightToLastGrade = 5
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = clngColumnRightToLastGrade Then
Application.EnableEvents = False
'offset selection, one row down, two cols to left
Target.Offset(1, -2).Select
Application.EnableEvents = True
End If
End Sub
This will set you one row down and to column C, everytime your selection changes to column E (=5).
You don't have to use a constant of course, you could specify the column to sense in the workbook, so your user might modify it easier by himself.
To make this as an optional feature, you could extend it to autogenerated code. What I have in mind is like a Ribbon-Button, which opens a setupForm to configure, and a Ribbon-Button to activate the configuration, which would place this code in the configured sheet. But this might be a bit over the top.
In Excel 2003, (may be different in Excel2007 ?!) the WorkSheet_Change event is triggered every time the value of a cell is changed wether it is by pressing enter, delete, selecting an other cell after modifying a cell or even when a vba script changes the value of a cell.
I would do something like that:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RefRange As Range
Set RefRange = Intersect(ActiveSheet.Columns("??????????"), ActiveSheet.UsedRange)
If Not Intersect(Target, RefRange) Is Nothing Then
Target.Offset(0, 1).EntireColumn.Range("A1").Select
'Target.Offset(0, 1).EntireColumn.Range("A65536").End(xlUp).Offset(1,0).Select
End If
End Sub