Results 1 to 4 of 4

Thread: Macro to generate a c++ header file using excel
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Feb 2014
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Macro to generate a c++ header file using excel

    Hi all,

    I am new to this foruma nd it looks great for me

    I am thinking to make a excel file which can generate a headre file for my c++ source file.
    Previoulsy we used to generate .h files using excel but i dont know the logic behind that(Hope some macros using for that).

    MY header file contains this many data and my intention is to give "MYapp Alpha 0.0.3" through excel file because the version number changes for each release. If i used excel file then I can edit that excel and it creates .h file for me, later some more informations i can make configurable through excel file

    #define APP_FLASH_APP_ID 0x123
    #define APP_VERSION_NUM "MYapp Alpha 0.0.3 "
    #define APP_PRODUCT_NAME "TPI "
    #define APP_DESCRIPTION_STR APP_PRODUCT_NAME APP_VERSION_NUM
    #define APP_RELEASE_DATE_STR "10/11/13"
    #define APP_SOFTWARE_PARTNUM_LEN 10

    Some valuable help or suggestions needed

    Have a great day

  2. #2
    MrExcel MVP Damon Ostrander's Avatar
    Join Date
    Feb 2002
    Location
    Denver, Colorado USA
    Posts
    4,239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to generate a c++ header file using excel

    Hi Sijith,

    Yes, this is easy to do in Excel. But there are a few options for you to consider before providing a solution:

    Where (what path or folder) should the .h be placed?

    - do you want it placed in the current (Excel) working folder? Or,

    - do you have a fixed folder location? Or,

    - would you like to browse for the .h file folder (like using a Save file dialog)?

    Do you want "MYapp Alpha 0.0.3" read from a cell in Excel so you can edit it there before generating the .h file?

    You mention other information you want to make configurable through Excel. Do you want to handle it the same way?

    Anyway, just rest assured that it is quite easy in Excel to write a text file (such as a .h file).

    Damon

  3. #3
    New Member
    Join Date
    Feb 2014
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to generate a c++ header file using excel

    I like to keep it in a fixed location say "c:/user/mydata" and dont want user to browse the location where it saved using excel.

    Like to keep "MYapp Alpha 0.0.3" in a cell in Excel so as u suggested I can edit any time I needed.

    My real need is to save it in 2 files one *.h and other *.opt. Both are fixed location.

  4. #4
    MrExcel MVP Damon Ostrander's Avatar
    Join Date
    Feb 2002
    Location
    Denver, Colorado USA
    Posts
    4,239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to generate a c++ header file using excel

    Hi again Sijith,

    Okay, suppose you have path, filename, and version number in cells B1:B3 like this:

    .... A .......| ....... B ..........
    Path: .......| C:/user/mydata
    File: ........| MyFile
    Version: ...| "MYapp Alpha 0.0.3"

    Then you can use this code to generate the .h and .opt files in the requested folder (path)

    Code:
    Sub WriteHeaderFiles()
       Dim Fpath      As String
       Dim Fname      As String
       Dim Fversion   As String
       
       Fversion = Range("B3")
       
       'set path to folder
       Fpath = Range("B1")
       If Right(Fpath, 1) <> "\" Then Fpath = Fpath & "\"
       
       'add filename to folder name to get complete path
       Fname = Range("B2")
       Fpath = Fpath & Fname
         
       'write .h file
       
       Open Fpath & ".h" For Output As #1
       
       Print #1, "#define APP_FLASH_APP_ID 0x123"
       Print #1, "#define APP_VERSION_NUM " & Fversion
       Print #1, "#define APP_PRODUCT_NAME ""TPI"""
       Print #1, "#define APP_DESCRIPTION_STR APP_PRODUCT_NAME APP_VERSION_NUM"
       Print #1, "#define APP_RELEASE_DATE_STR ""10/11/13"""
       Print #1, "#define APP_SOFTWARE_PARTNUM_LEN 10"
       
       Close #1
       
       'write .opt file
       
       Open Fpath & ".opt" For Output As #2
       
       Print #2, "#define APP_FLASH_APP_ID 0x123"   
       Print #2, "#define APP_VERSION_NUM " & Fversion
       Print #2, "#define APP_PRODUCT_NAME ""TPI"""
       Print #2, "#define APP_DESCRIPTION_STR APP_PRODUCT_NAME APP_VERSION_NUM"
       Print #2, "#define APP_RELEASE_DATE_STR ""10/11/13"""
       Print #2, "#define APP_SOFTWARE_PARTNUM_LEN 10"
       
       Close #2
    End Sub
    Please note that you do not enclose the path and file name in quotes, but do enclose the version in quotes.

    Keep Excelling.

    Damon
    Last edited by Damon Ostrander; Feb 25th, 2014 at 03:43 AM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •