Macro Toolworks and Perfect Keyboard Forums • Generate a letter/e-mail
Page 1 of 1

Generate a letter/e-mail

Posted: Wed Nov 23, 2016 6:02 pm
by Petr
This macro shows how to generate a letter from data that user picks in form.

Code: Select all

<#> Start of the macro
<cmds>
<#>  
<#> Initialize and show form: field for variable vCustomerName
<form_item>("f1","Customer name:","EDIT","","vCustomerName")
<#> Field - ListBox - for variable vService

<form_item>("f1","Service:","LIST","UNIX Virtual Server|NT Virtual Server|UNIX Dedicated Server|NT Dedicated Server","vService")
<#> ListBox for variable vDiscount

<form_item>("f1","Discount (in %):","LIST","0|5|10|20|30|50","vDiscount")
<#> ListBox for var. vStaff

<form_item>("f1","Support staff:","LIST","John McSmith|Adrian Mane|Brigita Largo","vStaff")
<#> Show form f1

<form_show>("f1","Customer Requests Information About Service","shell32.dll",0)
<#> If last key Esc or button ancel pressed - exit macro

<if_str>("_vCanceled == 1")
   <exitmacro>
<endif>

<#> Else start Notepad and make it active window
<execappex>("notepad.exe","","",0,0)

<#> Wait while program not opened...
<waitfor>("WIN","OPEN","[Untitled - Notepad|Notepad|#164|#18]",15,0)

<#> Activate Notepad window
<actwin>("[Untitled - Notepad|Notepad|#164|#18]",0,0,"no")

<#> Is Notepad window active?
<if_win>("[Untitled - Notepad|Notepad|#164|#18]","ACT",0)

<#> Assign right value for vPrice 
   <if_str>("vService==UNIX Virtual Server")
      <#>

      <varset>("vPrice=99.95","")
   <endif>
   <#>

   <if_str>("vService==NT Virtual Server")

      <#>  
      <varset>("vPrice=79.95","")
   <endif>
   <#>

   <if_str>("vService==UNIX Dedicated Server")
      <#>

      <varset>("vPrice=299.95","")
   <endif>
   <#>

   <if_str>("vService==NT Dedicated Server")
      <#>

      <varset>("vPrice=259.95","")
   <endif>
<#>  
<endif>

<#> Calculate variable vDiscountedPrice

<var_oper>(vDiscountedPrice,"%vPrice%-(%vPrice%*(%vDiscount%/100))",CALC_EXPRESSION,"2","", "0")

<#> Start writing letter here:
<keys>Dear <varout>("vCustomerName",0),

thank you very much for contacting us concerning our
web hosting services. Find below some facts about
the service you are interested in. We are glad we can 
offer you discounted price!

-------------------------------------------------------
<#> Send variable to Notepad
Customer: <varout>("vCustomerName",0)

<#> Send variable to Notepad
Service: <varout>("vService",0)
Bandwith: Unlimited
Price: <varout>("vPrice",0)/month
Discount: <varout>("vDiscount",0)%
Price after discount:<varout>("vDiscountedPrice",0)/month
-------------------------------------------------------

Feel free to contact us with any question any time.
<#> Send variable to Notepad 
<varout>("vStaff",0)
The Service Company Support

<#> End of the macro