Jump to content

Recommended Posts

Posted

Hello All,

I'm about to start working on a log building script and I was thinking about using an external ini file to control settings for the application that the user can edit and have the script use the new settings. Does anyone have any examples by chance of something simple? I just need an idea to help me get started.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Posted (edited)

You mean an INI file editor? If yes, you should try

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

For one of my projects, I use a text ini file with this format:

val1=true

val2=4

val3="text"

I read it, pass its contents to this function to populate variables from it:

Func ReadInputParms ( $InBuf ) ;$inBuf is the text contents of the ini file

dim $Input

dim $InTokens

dim $KeyVal

dim $Key

Dim $bDimmed = false

$InBuf = StringRight ( $InBuf, StringLen ( $InBuf ) - 1 )

if StringLen ( $InBuf ) = 0 Then

; Process the command line if no buffer was passed in

$Input = $CmdLineRaw

EndIf

$InTokens = StringSplit($InBuf, @CRLF, 1)

Dim $boolval, $numval, $stringval

for $i = 1 to $InTokens[0] ; loop through all input lines, and parse them

if StringLen ( $InTokens [ $i ] ) > 0 Then

Dim $array = StringSplit($InTokens[$i], "=")

$Key = StringLower($array[1])

if StringInStr($Key, chr(34)) > 0 Then $Key = StringReplace($Key, chr(34), "")

if StringInStr($InTokens[$i], "=") > 0 Then

$KeyVal = $array[2]

; remove start and end quotes if needed

if StringLeft($KeyVal, 1) = chr(34) and StringRight($KeyVal, 1) = chr(34) Then

$KeyVal = StringMid($KeyVal, 2, stringlen($KeyVal) - 2)

EndIf

Else

$KeyVal = True

EndIf

select

case StringLower ( $Key ) = "booleanvalue"

$boolval = ( StringLower($KeyVal) = "true" ) ; assign ini value to boolean variable

case StringLower ( $Key ) = "numericvalue"

$numval = $KeyVal * 1 ; assign ini value to numeric value

Case StringLower ( $Key ) = "stringval"

$stringval = $KeyVal ; assign ini value to string variable

case StringLower ( $Key ) = "/?" ; user asked for help, display usage

ShowUsage("")

Exit 0

case Else ; unexpected value, show usage

ShowUsage("Unknown parameter, '" & $InTokens[$i] & "'.")

Exit 1

EndSelect

EndIf

Next

EndFunc

Edited by rodent1
Posted

You mean an INI file editor? If yes, you should try

Thanks for the reply. Here is an example of what I mean.

So the application will have a button and a textpad. When the button is clicked it will send the following text to the textpad "You press a Button" I would like to have an ini file that button one get's it's text from. So the user could go in and make it say something different.

rodent1 seems to have done something like this before.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Posted

Here's something to demo a way to do it. It's very basic, but it allows you to create and change the INI file.

$IniFile = "text.ini"
$ButtonText = IniRead($IniFile, "news", "motd", " Hello ")
GUICreate("test", 200, 100)
$Button = GUICtrlCreateButton(" Say something ", 10, 10)
$Edit = GUICtrlCreateEdit("", 10, 40, 180, 50)
$Button2 = GUICtrlCreateButton(" Change INI text ", 100, 10)
GUISetState()
while 1
 $msg = GUIGetMsg()
 Switch $msg
  Case -3
   Exit
  case $Button
   $ButtonText = IniRead($IniFile, "news", "motd", " Hello ")
   GUICtrlSetData($Edit, $ButtonText)
  Case $Button2
   IniWrite($IniFile, "news", "motd", GUICtrlRead($Edit))
 EndSwitch
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

I've used an ini file for an app I made to merge PDFs for a 2000 page state public record file. The application is deployed in 4 offices for the managers, and the ini file and main documents sits on our NAS, available to all of them. When the app starts, the program pulls all of the program parameters: path to the current year's public record file, location of the last backup (for an undo feature), passwords, etc. The file in question gets copied to the local machine and a lock file is created on the NAS while a user is working on it, and all processing takes place on the local machine. When the user is finished, the completed file gets copied back to the NAS and the new parameters are saved to the ini.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Posted (edited)

AutoIt provides functions to read and write ini files.

Ooops - a bit late.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
×
×
  • Create New...