Converting script from V1 to V2

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Enitsrik
Posts: 8
Joined: 17 May 2023, 07:13

Converting script from V1 to V2

Post by Enitsrik » 30 May 2023, 06:32

Hi all,

I've tried to convert a script i Use when sending out e-mails from V1 to V2 but I keep running into problems and issues I don't know how to fix..

Is there anyone who could be able to "translate"?

Code: Select all

Sleep, 250
Gui, Destroy
Gui, Add, Text,, date
Gui, Add, MonthCal, vMyCalendar
Gui, Add, Text, xm y+10 w60, TRX time:
Gui, Add, Edit, x+m w100 vTime, HH:MM
Gui, Add, Text, xm y+10 w60, Invitation:
Gui, Add, Edit, x+m w100 vInvite, XXXXXX
Gui, Add, Text, xm y+10 w60, Name:
Gui, Add, Edit, x+m w100 vName, XXXX
Gui, Add, Text, xm y+10 w60, Adress:
Gui, Add, Edit, x+m w100 vAdress, 
Gui, Add, Text, xm y+10 w60, RSVP:
Gui, Add, Edit, x+m w100 vPhonenumber, XX XX XX XX 
Gui, Add, Button, default, OK
Gui, Show,, Invitation
return  

GuiClose:
ButtonOK:
Gui, Submit 

Sleep, 250
FormatTime, MyCalendar, %MyCalendar%, dd/MM/yyyy
Run, SendInvite.msg
sleep, 2000
Send, +{tab}
Sleep, 250
Send, {Right 22} %Invite%{sleep 50}{tab}Dear %Name%,{enter 2}You are hereby invited to my %Invite% {enter2}%MyCalendar% at %Time%{enter}%Adress%{enter 2}RSVP %Phonenumber%


ExitApp
Thank you again in advance for all you great support :D

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Converting script from V1 to V2

Post by mikeyww » 30 May 2023, 07:23

Code: Select all

#Requires AutoHotkey v2.0
gui1 := Gui(, 'Message')
gui1.AddText(, 'Date')
gui1.AddMonthCal('vdate')
; ------------------------------------------------------------
gui1.AddText('w60 Section'      , 'TRX time:'  )
gui1.AddText('wp'               , 'Invitation:')
gui1.AddText('wp'               , 'Name:'      )
gui1.AddText('wp'               , 'Address:'   )
gui1.AddText('wp'               , 'RSVP:'      )
; ------------------------------------------------------------
gui1.AddDateTime('ys w100 vtime', 'Time').SetFormat('HH:mm')
gui1.AddEdit('wp vinvite'       , 'XXX'        )
gui1.AddEdit('wp vname'         , 'Name'       )
gui1.AddEdit('wp vaddress'      , 'Address'    )
gui1.AddEdit('wp vphonenumber'  , 'Phone'      )
; ------------------------------------------------------------
gui1.AddButton('xm w206 Default', 'OK').OnEvent('Click', OK_Click)
gui1.Show

OK_Click(btn, info) {
 g := gui1.Submit()
 Sleep 250
 Run 'SendInvite.msg'
 Sleep 2000
 Send '+{Tab}'
 Sleep 250
 Send '{Right 22}'
 SendText g.invite
 Sleep 50
 SendText '`tDear ' g.name ',`n`nYou are hereby invited to my ' g.invite '.`n`n'
        . FormatTime(g.date, 'dd/MM/yyyy') ' at ' FormatTime(g.time, 'HH:mm')
        . '`n`n' g.address '`n`nRSVP ' g.phonenumber
}

Enitsrik
Posts: 8
Joined: 17 May 2023, 07:13

Re: Converting script from V1 to V2

Post by Enitsrik » 31 May 2023, 06:47

mikeyww wrote:
30 May 2023, 07:23

Code: Select all

#Requires AutoHotkey v2.0
gui1 := Gui(, 'Message')
gui1.AddText(, 'Date')
gui1.AddMonthCal('vdate')
; ------------------------------------------------------------
gui1.AddText('w60 Section'      , 'TRX time:'  )
gui1.AddText('wp'               , 'Invitation:')
gui1.AddText('wp'               , 'Name:'      )
gui1.AddText('wp'               , 'Address:'   )
gui1.AddText('wp'               , 'RSVP:'      )
; ------------------------------------------------------------
gui1.AddDateTime('ys w100 vtime', 'Time').SetFormat('HH:mm')
gui1.AddEdit('wp vinvite'       , 'XXX'        )
gui1.AddEdit('wp vname'         , 'Name'       )
gui1.AddEdit('wp vaddress'      , 'Address'    )
gui1.AddEdit('wp vphonenumber'  , 'Phone'      )
; ------------------------------------------------------------
gui1.AddButton('xm w206 Default', 'OK').OnEvent('Click', OK_Click)
gui1.Show

OK_Click(btn, info) {
 g := gui1.Submit()
 Sleep 250
 Run 'SendInvite.msg'
 Sleep 2000
 Send '+{Tab}'
 Sleep 250
 Send '{Right 22}'
 SendText g.invite
 Sleep 50
 SendText '`tDear ' g.name ',`n`nYou are hereby invited to my ' g.invite '.`n`n'
        . FormatTime(g.date, 'dd/MM/yyyy') ' at ' FormatTime(g.time, 'HH:mm')
        . '`n`n' g.address '`n`nRSVP ' g.phonenumber
}
Thank you so much! It worked like a charm! :bravo:

Enitsrik
Posts: 8
Joined: 17 May 2023, 07:13

Re: Converting script from V1 to V2

Post by Enitsrik » 31 May 2023, 06:51

mikeyww wrote:
30 May 2023, 07:23

Code: Select all

#Requires AutoHotkey v2.0
gui1 := Gui(, 'Message')
gui1.AddText(, 'Date')
gui1.AddMonthCal('vdate')
; ------------------------------------------------------------
gui1.AddText('w60 Section'      , 'TRX time:'  )
gui1.AddText('wp'               , 'Invitation:')
gui1.AddText('wp'               , 'Name:'      )
gui1.AddText('wp'               , 'Address:'   )
gui1.AddText('wp'               , 'RSVP:'      )
; ------------------------------------------------------------
gui1.AddDateTime('ys w100 vtime', 'Time').SetFormat('HH:mm')
gui1.AddEdit('wp vinvite'       , 'XXX'        )
gui1.AddEdit('wp vname'         , 'Name'       )
gui1.AddEdit('wp vaddress'      , 'Address'    )
gui1.AddEdit('wp vphonenumber'  , 'Phone'      )
; ------------------------------------------------------------
gui1.AddButton('xm w206 Default', 'OK').OnEvent('Click', OK_Click)
gui1.Show

OK_Click(btn, info) {
 g := gui1.Submit()
 Sleep 250
 Run 'SendInvite.msg'
 Sleep 2000
 Send '+{Tab}'
 Sleep 250
 Send '{Right 22}'
 SendText g.invite
 Sleep 50
 SendText '`tDear ' g.name ',`n`nYou are hereby invited to my ' g.invite '.`n`n'
        . FormatTime(g.date, 'dd/MM/yyyy') ' at ' FormatTime(g.time, 'HH:mm')
        . '`n`n' g.address '`n`nRSVP ' g.phonenumber
}
Could I ask you to help me with a different script?

I've used another hotkey were there were preprogrammed e-mail address' that the user could choose in a drop down menu.
I cannot get it to work in V2 no matter how I try.

Code: Select all

Sleep, 250
Gui, Destroy
Gui, Font, s10
Gui, Add, Text, w110, Choose city:
Gui, Add, DropDownList, ym w200 vCity, New York|Paris|Berlin|
Gui, Add, Text, xm y+10 w110, Name:
Gui, Add, Edit, x+m w200 vName, XXXXXX
Gui, Add, Button, xm  w323 Default, OK 
Gui, Show,, Location
return  


GuiClose:
ButtonOK:
Gui, Submit 

Sleep, 250
Run, Booking e-mail.msg

sleep, 2000
Send, +{tab 3}
Sleep 550
Send, ^a
Sleep, 550

If (City = "New York")
{
Send, [email protected]
Sleep, 500
Send, {enter}
}

If (City = "Paris")
{
Send, [email protected]
Sleep, 500
Send, {enter}
}

If (City = "Berlin")
{
Send, [email protected]
Sleep, 500
Send, {enter}
}



Sleep, 550
Send {tab 2}{end} - booking at %City%{tab}
Sleep, 550
Send, {right 3} Hi %Name%.{enter 2}Please see enclosed for booking details.
Sleep, 550
Send, !n
Sleep, 550
Send, AF
Sleep, 550
Send, {down}
Sleep, 250
Send, {enter}

ExitApp

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Converting script from V1 to V2

Post by mikeyww » 31 May 2023, 07:04

Code: Select all

#Requires AutoHotkey v2.0
email := Map(
            'New York', '[email protected]'
          , 'Paris'   , '[email protected]'
          , 'Berlin'  , '[email protected]'
         )
city := []
For cityName in email
 city.Push(cityName)
gui1 := Gui(, 'E-mail')
gui1.SetFont('s10')
gui1.AddDDL('w250 vcity', city)
gui1.AddButton('wp Default', 'OK').OnEvent('Click', go)
gui1.Show

go(btn, info) {
 g := gui1.Submit()
 MsgBox email[g.city], 'E-mail address'
}

Enitsrik
Posts: 8
Joined: 17 May 2023, 07:13

Re: Converting script from V1 to V2

Post by Enitsrik » 02 Jun 2023, 06:15

mikeyww wrote:
31 May 2023, 07:04

Code: Select all

#Requires AutoHotkey v2.0
email := Map(
            'New York', '[email protected]'
          , 'Paris'   , '[email protected]'
          , 'Berlin'  , '[email protected]'
         )
city := []
For cityName in email
 city.Push(cityName)
gui1 := Gui(, 'E-mail')
gui1.SetFont('s10')
gui1.AddDDL('w250 vcity', city)
gui1.AddButton('wp Default', 'OK').OnEvent('Click', go)
gui1.Show

go(btn, info) {
 g := gui1.Submit()
 MsgBox email[g.city], 'E-mail address'
}
Thank you so much for the help!
I've tried to incorporate your coding into the script, but I cannot get it to work.

I'm trying to make a script were the user can choose the pre entered e-mail adress based on city location, then have the hotkey open up a presaved e-mail file, copy in the chosen e-mail adress, adding some words to the e-mail subject and
How can I get your coding to blend into the script that used to work in V1?

Code: Select all

Sleep, 250
Gui, Destroy
Gui, Font, s10
Gui, Add, Text, w110, Choose city:
Gui, Add, DropDownList, ym w200 vCity, New York|Paris|Berlin|
Gui, Add, Text, xm y+10 w110, Name:
Gui, Add, Edit, x+m w200 vName, XXXXXX
Gui, Add, Button, xm  w323 Default, OK 
Gui, Show,, Location
return  


GuiClose:
ButtonOK:
Gui, Submit 

Sleep, 250
Run, Booking e-mail.msg

sleep, 2000
Send, +{tab 3}
Sleep 550
Send, ^a
Sleep, 550

If (City = "New York")
{
Send, [email protected]
Sleep, 500
Send, {enter}
}

If (City = "Paris")
{
Send, [email protected]
Sleep, 500
Send, {enter}
}

If (City = "Berlin")
{
Send, [email protected]
Sleep, 500
Send, {enter}
}



Sleep, 550
Send {tab 2}{end} - booking at %City%{tab}
Sleep, 550
Send, {right 3} Hi %Name%.{enter 2}Please see enclosed for booking details.
Sleep, 550
Send, !n
Sleep, 550
Send, AF
Sleep, 550
Send, {down}
Sleep, 250
Send, {enter}

ExitApp
It used to work in V1 but I cannot get it to work in V2 no matter what I've tried.
Coding V2 has been like switching from English to Spanish only equipped with half a dictionary - so I'm sorry for all the "stupid" questions.

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Converting script from V1 to V2

Post by mikeyww » 02 Jun 2023, 06:40

Examining the AHK documentation will help, because it shows you the syntax for the various functions. Examples are included for each.

Code: Select all

#Requires AutoHotkey v2.0
email := Map(
            'New York', '[email protected]'
          , 'Paris'   , '[email protected]'
          , 'Berlin'  , '[email protected]'
         )
city := []
For cityName in email
 city.Push(cityName)
gui1 := Gui(, 'Location'), gui1.SetFont('s10')
; -- Column 1 --------------------------------
gui1.AddText(      , 'Choose city:')
gui1.AddText('wp'  , 'Name:')
; -- Column 2 --------------------------------
gui1.AddDDL( 'ym vcity', city)
gui1.AddEdit('wp vname', 'XXXX')
; --------------------------------------------
gui1.AddButton('xm w236 Default', 'OK').OnEvent('Click', go)
gui1.Show

go(btn, info) {
 g := gui1.Submit()
 Run 'Booking e-mail.msg'
 Sleep 2000
 SendEvent '+{Tab 3}'
 Sleep 550
 Send '^a'
 Sleep 550
 SendText email[g.city]
 Sleep 500
 Send '`n'
 Sleep 550
 SendEvent '`t`t{End}'
 SendText ' - booking at ' g.city '`t'
 Sleep 550
 SendEvent '{Right 3}'
 SendText ' Hello, ' g.name '.`n`nPlease see enclosed for booking details.'
 Sleep 550
 Send '!n'
 Sleep 550
 SendEvent 'af'
 Sleep 550
 Send '{Down}'
 Sleep 250
 Send '`n'
 ExitApp
}

Post Reply

Return to “Ask for Help (v2)”