Insert current date to a file name

Share your macros, knowledge, solutions, services, ...
Post Reply
Petr
Posts: 106
Joined: Tue Oct 18, 2016 1:12 pm

Insert current date to a file name

Post by Petr » Wed Nov 23, 2016 5:53 pm

This macro sample shows how to insert current date to a selected file.

Code: Select all

<#> Start of the macro
<cmds>

<#> Start definition of procedure GetDateString  with parameter parDateString  
<proc_def_begin>(GetDateString, "&parDateString&")

<#> Assign value to variable parDateString
<varset>("parDateString=-%_vCurrDate_Year%-%_vCurrDate_MM%-%_vCurrDate_DD%","")

<#> End of procedure
<proc_def_end>

<#> Start definition of procedure InsertDateToFileName with parameter parFileName 
<proc_def_begin>(InsertDateToFileName, "&parFileName&")

<#> Call procedure GetDateString with param. lpvDateString
<proc_call>(GetDateString,"lpvDateString")

<#> Count to vbLnt length of string parFileName
<var_oper>(vbLnt,"%parFileName%",STR_LENGTH,"","", "0")

<#> Begin loop for var. vbLnt
<begloop>(vbLnt)
   
   <var_oper>(vbInx,"%vbLnt%-%_vLoopCounter%",CALC_EXPRESSION,"0","", "0")
   <var_oper>(vbChar,"%parFileName%",STR_GET_CHAR,"vbInx","", "0")

   <#> If found char "."
   <if_str>("vbChar==.")

      <#> Insert var. lpvDateString before "."
      <var_oper>(parFileName,"%parFileName%",STR_INSERT,"vbInx","%lpvDateString%", "0")

      <#> Go to label lbl_b_End 
      <goto>("lbl_b_End")
   <endif>
<endloop>

<#> Append var. lpvDateString at the end of variable parFileName ( char "." not found ...)
<var_oper>(parFileName,"%parFileName%",STR_APPEND,"%lpvDateString%","", "0")

<#> Label lbl_b_End
<label>("lbl_b_End")

<#> End of procedure
<proc_def_end>


<#> Macro execution starts here
<var_oper>(vFile,"",SELECT_FILE," ","", "0")

<#> If last key ESC or button Cancel
<if_str>("_vCanceled == 1")
   <exitmacro>
<endif>

<#> Else call procedure InsertDateToFileName with parameter vFile
<proc_call>(InsertDateToFileName,"vFile")

<#> Show message with new file name...
<msg>(-100,-100,"vFile","Message",1)\

<#> End of the macro

Post Reply