Jump to content

How should .ini be set up?


Recommended Posts

So I got a script done for running a bunch of reports we do in the morning and instead of having the reports hard coded in the program I was thinking of putting them in an .ini file. I'm just unsure of how it should be formatted.. It would need to have report name, export directory, date to run from (optional), date to run to (optional), and any special replacement varables..

Should I give each report it's seperate section? i.e.

[report 1]

ExportDir = c:\

DateFrom = $Yesterday

DateTo = $Today

or something else..

actually.. now that I wrote it out it makes sense to have it like above.. unless anyone else has a better/different way :D

Link to comment
Share on other sites

So I got a script done for running a bunch of reports we do in the morning and instead of having the reports hard coded in the program I was thinking of putting them in an .ini file. I'm just unsure of how it should be formatted.. It would need to have report name, export directory, date to run from (optional), date to run to (optional), and any special replacement varables..

Should I give each report it's seperate section? i.e.

[report 1]

ExportDir = c:\

DateFrom = $Yesterday

DateTo = $Today

or something else..

actually.. now that I wrote it out it makes sense to have it like above.. unless anyone else has a better/different way :D

That looks great, but just remember that you will have to Execute() any AutoIt variables contained in the .ini
[font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
Link to comment
Share on other sites

So I got a script done for running a bunch of reports we do in the morning and instead of having the reports hard coded in the program I was thinking of putting them in an .ini file. I'm just unsure of how it should be formatted.. It would need to have report name, export directory, date to run from (optional), date to run to (optional), and any special replacement varables..

Should I give each report it's seperate section? i.e.

[report 1]
ExportDir = c:\
DateFrom = $Yesterday
DateTo = $Today

or something else..

actually.. now that I wrote it out it makes sense to have it like above.. unless anyone else has a better/different way :D

Don't try to code actual variable names into the INI, it's a really bad idea that only looks like it saves you work. It will come back to bite you later. Just use key words like "Yesterday" or "Today", and when your script interprets that field, it will know what to do by simple string tests with If/Then, Select or Switch.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Don't try to code actual variable names into the INI, it's a really bad idea that only looks like it saves you work. It will come back to bite you later. Just use key words like "Yesterday" or "Today", and when your script interprets that field, it will know what to do by simple string tests with If/Then, Select or Switch.

:)

Ahh, good ideal. Thanks!

One thing I thought of.. is there a way to add comments to an ini file that the Iniread functions will ignore, or will I have to make my own loop/function to ignore them?

Link to comment
Share on other sites

Ahh, good ideal. Thanks!

One thing I thought of.. is there a way to add comments to an ini file that the Iniread functions will ignore, or will I have to make my own loop/function to ignore them?

Hmm, can't find an edit button for my last post.. Playing around with IniRead, IniReadSection.. etc it looks like it ignores any weird things, like (blah blah comments) or things that aren't in the format value=key

Perfect for me!

In case anyone was curious.. (ya I know, crappy choices for variables but this is my scratch pad, I redo them when I actually implement it :) )

ini file

[<report name>]  (section name)
<key>=<value>
ExportDir=
StartDate= (optional)
EndDate= (optional)

[main]
MainExport="c:\temp\"


[report 1]
ExportDir=c:\
StartDate=today
EndDate=today
SaveFileFormat="%filename%_today"

[report x]
ExportDir=c:\temp\
StartDate=$yesterday
EndDate=$yesterday
SaveFileFormat="%filename%_yesterday"

(replace %filename% with... selected name..)

get the stuff from the ini file..

$temp = IniReadSectionNames("c:\temp\reports.ini")
for $x = 1 to $temp[0]
    MsgBox(0, "", $temp[$x])
    ;$z = IniRead("c:\temp\reports.ini", $temp[$x], "ExportDir", "")
    $z = IniReadSection("C:\temp\reports.ini", $temp[$x])
    Global $ExportDir, $StartDate, $EndDate, $SaveFileFormat
    for $z2 = 1 to $z[0][0]
        MsgBox(4096, "", "Key:  " & $z[$z2][0] & @CRLF & "Value:  " & $z[$z2][1])
        Switch $z[$z2][0]  ;get the key
        Case "ExportDir"
            $ExportDir = $z[$z2][1]
        Case "StartDate"
            $StartDate = $z[$z2][1]
        Case "EndDate"
            $EndDate = $z[$z2][1]
        Case "SaveFileFormat"
            $SaveFileFormat = $z[$z2][1]
        EndSwitch
        
        
            
    Next
        
        MsgBox(4096, "vars", "Export Dir:  " & $ExportDir & @CRLF & _
                "StartDate:  " & $StartDate & @CRLF & _
                "EndDate:  " & $EndDate & @CRLF & _
                "SaveFileFormat:  " & $SaveFileFormat)
    
Next
Edited by Danith
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...