FireLord Posted November 18, 2007 Share Posted November 18, 2007 (edited) If I input a string in my Input in my program it automatically writes that string to an INI. Before it writes the string what code would "search" the INI for the string I typed in the input? And if it finds a string that matches the one that was just typed it would not INIWrite the new string. Thanks in advance. Edited November 18, 2007 by FireLord [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
Nahuel Posted November 18, 2007 Share Posted November 18, 2007 Well.. IniRead and IniWrite are what you need... Short example $Input=InputBox("","type hello") $String=IniRead("myini.ini","section","key","") If $String="" Then IniWrite("myini.ini","section","key",$Input) Else MsgBox(0,"",$Input & " was found in the ini.") EndIf Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 That doesn't work. [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
Nahuel Posted November 18, 2007 Share Posted November 18, 2007 (edited) 1º - excuse me for trying to help.2º - it does work.3º - What's the need for doing that? If the string is there, what would happen if you write it again? Answer: nothing. For example, if you have this ini.[General] Key="value"If you type "value" in an inputbox, it's pointless to check if "value" is already in the ini or not, cos if it is it will just write it again! You are still going to write it if it's not there anyway...Get my point? Edited November 18, 2007 by Nahuel Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 (edited) 1º - excuse me for trying to help. 2º - it does work. 3º - What's the need for doing that? If the string is there, what would happen if you write it again? Answer: nothing. For example, if you have this ini. [General] Key="value" If you type "value" in an inputbox, it's pointless to check if "value" is already in the ini or not, cos if it is it will just write it again! You are still going to write it if it's not there anyway... Get my point?Try reading, Taken from my post: And if it finds a string that matches the one that was just typed it would not INIWrite the new string. My point is to check the INI for a string that I just typed. Let's say it is "autoit". I need something to search the INI for "autoit" (the string I just typed) and if it finds it in the INI it will NOT write "autoit" to the INI. Get it? Edited November 18, 2007 by FireLord [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
Valuater Posted November 18, 2007 Share Posted November 18, 2007 search all?? section names, sections, keys or ??? 8) Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 search all??section names, sections, keys or ??? 8)Search just the key. [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
Valuater Posted November 18, 2007 Share Posted November 18, 2007 how is the "section" selected by you or is there just one or ?? 8) Link to comment Share on other sites More sharing options...
Nahuel Posted November 18, 2007 Share Posted November 18, 2007 A standard ini file looks like: [sectionName] Key=Value You want to know if the value that you entered in the inputbox was previously written in any key of the ini file? Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 how is the "section" selected by you or is there just one or ??8)there's only one section in my ini [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 You want to know if the value that you entered in the inputbox was previously written in any key of the ini file?there's only one key. [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
Nahuel Posted November 18, 2007 Share Posted November 18, 2007 1 section + 1 key = IniRead() Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 1 section + 1 key = IniRead() You mentioned that already but it didn't work. What about StringInStr? [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
Nahuel Posted November 18, 2007 Share Posted November 18, 2007 But it's an ini file. All you are interested about is the value of your key, which is what IniRead() does. When the user types something in an inputbox, use IniRead to see if your key already has that value. If IniRead() returns the same string that was entered by the user, then do nothing. Else, write the value in the key. Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 (edited) My code:If $var = $Input Then MsgBox(64, "Error", "", 5) Else INIWrite("C:\test.ini", "Section", "Key", IniRead("C:\test.ini", "Section", "Key", "") & GUICtrlRead($Input) & ",") GUICtrlSetData($Input, "") EndIfThe line 'If $var = $Input means if my INI is equal to the input I just entered then do nothing right? Like you said?Otherwise INIWrite? Well that's what I did and it doesn't work.Any suggestions that will "search" the INI for the value I inputted besides INIRead because it doesn't work for this specifici purpose. Edited November 18, 2007 by FireLord [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 ...anyone? [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
WaterBender Posted November 18, 2007 Share Posted November 18, 2007 My code:If $var = $Input Then MsgBox(64, "Error", "", 5) Else INIWrite("C:\test.ini", "Section", "Key", IniRead("C:\test.ini", "Section", "Key", "") & GUICtrlRead($Input) & ",") GUICtrlSetData($Input, "") EndIfThe line 'If $var = $Input means if my INI is equal to the input I just entered then do nothing right? Like you said?Otherwise INIWrite? Well that's what I did and it doesn't work.Any suggestions that will "search" the INI for the value I inputted besides INIRead because it doesn't work for this specifici purpose.yeah im having a similar problem. Link to comment Share on other sites More sharing options...
Bowmore Posted November 18, 2007 Share Posted November 18, 2007 ...anyone? Do you want you ini file to look something like this? [Section] Key=Value,Another value,something. Do you want to add extra values to the key without repeating a value already entered? If I have understood correctly then this should work. Dim $InputValue = '' Dim $PreviousEntry = '' ; $InputValue = GUICtrlRead($Input) $InputValue = InputBox("Input","Enter a value") $PreviousEntry = IniRead("C:\test.ini", "Section", "Key", "") If StringInStr($PreviousEntry,$InputValue & ',') Then MsgBox(64, "Error", "Entry already exists", 5) Else INIWrite("C:\test.ini", "Section", "Key", $PreviousEntry & $InputValue & ",") ; GUICtrlSetData($Input, "") EndIf The reason people have been confused as to what you are trying to do is that this is not the way ini files are supposed to be used. In normal usage you should only have one value for each key. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 Do you want you ini file to look something like this? [Section] Key=Value,Another value,something. Do you want to add extra values to the key without repeating a value already entered? If I have understood correctly then this should work. Dim $InputValue = '' Dim $PreviousEntry = '' ; $InputValue = GUICtrlRead($Input) $InputValue = InputBox("Input","Enter a value") $PreviousEntry = IniRead("C:\test.ini", "Section", "Key", "") If StringInStr($PreviousEntry,$InputValue & ',') Then MsgBox(64, "Error", "Entry already exists", 5) Else INIWrite("C:\test.ini", "Section", "Key", $PreviousEntry & $InputValue & ",") ; GUICtrlSetData($Input, "") EndIf The reason people have been confused as to what you are trying to do is that this is not the way ini files are supposed to be used. In normal usage you should only have one value for each key. I just want to search the one key in the INI file everytime I input something in the input for the thing I just inputted. If there is something that matches with the input thne it will not INIWrite, otherwise INIWrite. [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] Link to comment Share on other sites More sharing options...
FireLord Posted November 18, 2007 Author Share Posted November 18, 2007 Never mind my previous post. It's working. Thank you very much. [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center] 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