Jump to content

Check for a given string in INI


FireLord
 Share

Recommended Posts

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 by FireLord

[center]See the Helpfile[/center]

While Alive()
	 DrinkWine();
}
[center][/center]
Link to comment
Share on other sites

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 by Nahuel
Link to comment
Share on other sites

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 by FireLord

[center]See the Helpfile[/center]

While Alive()
	 DrinkWine();
}
[center][/center]
Link to comment
Share on other sites

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

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, "")

EndIf

The 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 by FireLord

[center]See the Helpfile[/center]

While Alive()
	 DrinkWine();
}
[center][/center]
Link to comment
Share on other sites

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, "")

EndIf

The 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

...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

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

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...