variable on my macro

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gdurieux
Posts: 7
Joined: 22 Jan 2016, 04:45

variable on my macro

25 Jan 2016, 08:56

Hi all,

I progress on the creation of my macro with help of this forum.
I have new problem because i would like to improve my job.
In my macro i often use sleep command and after few test i think it can be good if the number after sleep is defined by user. so i want to add after the message box the possibility for the user to type one number in second and this number will be a variable. This variable will be use after sleep.

for exemple : the user type 2 if he want 2 secondes and the variable will be sleep, %var%*1000 (to convert in millisecond)

i'm sure it's possible but i don't find the correct way to do this.

Thanks
Guillaume Durieux
Attachments
macro annotation guillaume durieux janv2016.txt
(1.39 KiB) Downloaded 45 times
SifJar
Posts: 398
Joined: 11 Jan 2016, 17:52

Re: variable on my macro

25 Jan 2016, 09:15

To do this, you need to use an expression. Your example is close to correct, however in expressions, variables are not wrapped in % symbols. Instead, plain text is interpreted as variables, and literal text must be in quotation marks ("). When you put %var%, this tells AHK to use the value stored in var as the name of variable. So for your example, you would use Sleep, var*1000.

With what you have, AHK is looking at the variable var, seeing that it contains for example "2" and then trying to find a variable named 2, and use the contents of that variable, instead of var.

Hope that makes sense.
japankid3000
Posts: 43
Joined: 14 Nov 2015, 09:58

Re: variable on my macro

25 Jan 2016, 20:18

Why couldn't you just post your code, why make it so you have to download?
gdurieux
Posts: 7
Joined: 22 Jan 2016, 04:45

Re: variable on my macro

26 Jan 2016, 03:22

Hi all,

I progress but it's not working well for the moment.
This is the actual version : Guillaume
SifJar
Posts: 398
Joined: 11 Jan 2016, 17:52

Re: variable on my macro

26 Jan 2016, 05:31

Code: Select all

MsgBox ,,Lancement de la macro Annotation cree par Guillaume Durieux,La macro est prete a demarrer. Pour son bon fonctionnement il faut obligatoirement qu'aucune application ne soit lancee et qu'une image soit selectionnee. Il faut aussi qu'un document vierge ait été ouvert dans le traitement de texte. Merci de cliquer sur le bouton OK ou alors d'appuyer sur la touche ENTREE de votre clavier.,
InputBox, var_sleep, Definition des temps de pause, Merci de taper un chiffre entre 1 et 10. Plus ton ordinateur est lent et plus le chiffre devra se rapprocher de 10. Essaye d'abord  un petit chiffre et si la macro ne fonctionne pas alors il faudra taper un chiffre plus important,,,,,,,, Default]
Send ^c							; copie l'image en mémoire
Sleep, var_sleep*1000
Send !{tab}						; retourne dans le document vierge		
Sleep, var_sleep*1000
Send ^v							; colle l'image dans le document vierge				
FileRemoveDir, C:\annotation_gdurieux ,1		; supprime le dossier c:\annotation_gdurieux
FileCreateDir, C:\annotation_gdurieux			; crée le dossier c:\annotation_gdurieux de telle qu'on soit sur qu'il soit vierge
Send ^c!{tab}^v 					; realise le copie/coller de l'image concernée
Sleep, var_sleep*1000
Send !{tab}
Sleep, var_sleep*1000
Send ^v
Sleep, var_sleep*1000
Send ^a!f!d						; exécute raccourci ctrl+a puis le raccourci alt+f
Sleep, var_sleep*1000						; temporise 1 seconde
Send !s							; exécute raccourci alt+s
Sleep, var_sleep*1000						; temporise 1 seconde
Send !x							; exécute raccourci alt+x
Sleep, var_sleep*1000						; temporise une seconde
Send c:\annotation_gdurieux\annotation			; indique le nom et le dossier d'enregistrement du fichier pdf
Sleep, var_sleep*1000
Send {Enter}
Sleep, var_sleep*1000
Run c:\annotation_gdurieux\annotation.pdf		; ouvre le fichier pdf precedement crée


If you put your code into your post like I have done, purple will be more inclined to help as they won't have to download a file just to even try! I haven't made any changes to the code, just posted it so people can at least see it without having to download it.

You say it's "not working well" - explain please. What is going wrong? What is happening that shouldn't be, or isn't happening that should be?
gdurieux
Posts: 7
Joined: 22 Jan 2016, 04:45

Re: variable on my macro

26 Jan 2016, 05:50

My actual problem is to multiply by 1000 the variable var_sleep.
I try with sleep, var_sleep*1000 but it's not working.

Thank you
Guillaume Durieux
grant
Posts: 323
Joined: 14 Oct 2015, 17:27

Re: variable on my macro

26 Jan 2016, 06:21

Input box is working and the sleep is working as expected.

Code: Select all

f2::
InputBox, var_sleep, Second to sleep
msgbox, Sleep for %var_sleep% seconds
Sleep, var_sleep*1000
msgbox, done, lets check that again for %var_sleep% seconds
Sleep, var_sleep*1000
msgbox, done
return
Could it be something else that is causing the program to stall somewhere?
gdurieux
Posts: 7
Joined: 22 Jan 2016, 04:45

Re: variable on my macro

26 Jan 2016, 09:58

Sorry, i made a mistake, in fact it was working but i forget to change me keybord shortcut so i was launching the the version 2 and not the version 2.1 of the macro.

This is the complete text of the macro :

Code: Select all

MsgBox ,,Lancement de la macro Annotation cree par Guillaume Durieux,La macro est prete a demarrer. Pour son bon fonctionnement il faut obligatoirement qu'aucune application ne soit lancee et qu'une image soit selectionnee. Il faut aussi qu'un document vierge ait été ouvert dans le traitement de texte. Merci de cliquer sur le bouton OK ou alors d'appuyer sur la touche ENTREE de votre clavier.,
InputBox, var_sleep, Definition du temps de pause, Merci de taper un chiffre entre 1 et 10. Plus ton ordinateur est lent et plus le chiffre devra se rapprocher de 10. Essaye d'abord  un petit chiffre et si la macro ne fonctionne pas alors il faudra taper un chiffre plus important,,,,,,,,1
Send ^c							; copie l'image en mémoire
Sleep, var_sleep*1000
Send !{tab}						; retourne dans le document vierge		
Sleep, var_sleep*1000
Send ^v							; colle l'image dans le document vierge				
FileRemoveDir, C:\annotation_gdurieux ,1		; supprime le dossier c:\annotation_gdurieux
FileCreateDir, C:\annotation_gdurieux			; crée le dossier c:\annotation_gdurieux de telle qu'on soit sur qu'il soit vierge
Send ^c!{tab}^v 					; realise le copie/coller de l'image concernée
Sleep, var_sleep*1000
Send !{tab}
Sleep, var_sleep*1000
Send ^v
Sleep, var_sleep*1000
Send ^a!f!d						; exécute raccourci ctrl+a puis le raccourci alt+f
Sleep, var_sleep*1000						; temporise 1 seconde
Send !s							; exécute raccourci alt+s
Sleep, var_sleep*1000						; temporise 1 seconde
Send !x							; exécute raccourci alt+x
Sleep, var_sleep*1000						; temporise une seconde
Send c:\annotation_gdurieux\annotation			; indique le nom et le dossier d'enregistrement du fichier pdf
Sleep, var_sleep*1000
Send {Enter}
Sleep, var_sleep*1000
Run c:\annotation_gdurieux\annotation.pdf		; ouvre le fichier pdf precedement crée
Thanks for your help
Guillaume Durieux

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: TAC109 and 80 guests