Solomon Posted March 8, 2008 Share Posted March 8, 2008 I'm trying to have a default value in foo.ini. By default, I mean that if there is no value present, a default value will be automatically inserted. This is the contents of foo.ini.[section1] key1 = folder1 key2 = key3 = folder3key2 is intentionally left blank. Sometimes there will be a value, other times it will be blank. key1 and key3 will always have values. When there's a value in key2, I want that value to be used. When it's blank, I want the value of c:\folder to be inserted. The values in key1, key2 & key3 are being passed on (via Send) to 3 different controls. Everything works fine, as long as there is a value in key2. key1 and key3 always have their values sent, but when there is no value in key2, nothing is being sent to the 2nd control. If I put a value into key2, that value is sent.This is the code I have.$foldername1 = IniRead("foo.ini", "section1", "key1") $foldername2 = IniRead("foo.ini", "section1", "key2", "c:\folder") $foldername3 = IniRead("foo.ini", "section1", "key3") ControlClick("Name_of_window", "", 1) Send($foldername1) ControlClick("Name_of_window", "", 2) Send($foldername2) ControlClick("Name_of_window", "", 3) Send($foldername3)I've read up on IniRead in the help file, and it seems to say that c:\folder will be inserted in the event of the key being blank, but that's not happening for me. Am I misunderstanding the help file? I'm using WinXP SP2, SciTe 1.74 to write the code with, and AutoIt 3.1.1. All help is greatly appreciated. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 8, 2008 Developers Share Posted March 8, 2008 The default value is used when the key is not present in the INI file. Since it is it returns its value. In this case "" So just add an If statement testing for "" ...something like: If $foldername2 = "" then $foldername2 = "c:\folder" SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Solomon Posted March 8, 2008 Author Share Posted March 8, 2008 Blimey that was quick! Thank you very much! Link to comment Share on other sites More sharing options...
ByteMyCookies Posted March 8, 2008 Share Posted March 8, 2008 $foldername2 = IniRead("foo.ini", "section1", "key2", "c:\folder") Will return c:\folder IF the key isn't found I whipped this up for you, It will evalute the key and give you some results. $Foldername2 = IniRead ( "Foo.ini", "section1", "key2", "Key not found") If $Foldername2 = "Key not found." Then Msgbox(48,"Test","Key not found, adding it to InI File with C:\folder as value") IniWrite ( "Foo.ini", "section1", "key2", "C:\folder") ElseIf $Foldername2 NOT "C:\folder" Then Msgbox(48,"Test","Key found, But it isn't C:\folder it is:" & @LF & $Foldername2) EndIf My Scripts,[topic="65986"]AI Example[/topic] ,Capable of Emotion! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now