Jump to content
Sign in to follow this  
FireLord

Check for a given string in INI

Recommended Posts

FireLord

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]

Share this post


Link to post
Share on other sites
Nahuel

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

Share this post


Link to post
Share on other sites
FireLord

That doesn't work.


[center]See the Helpfile[/center]
While Alive()
	 DrinkWine();
}
[center][/center]

Share this post


Link to post
Share on other sites
Nahuel

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

Share this post


Link to post
Share on other sites
FireLord

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]

Share this post


Link to post
Share on other sites
Valuater

search all??

section names, sections, keys or ???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
FireLord

search all??

section names, sections, keys or ???

8)

Search just the key.


[center]See the Helpfile[/center]
While Alive()
	 DrinkWine();
}
[center][/center]

Share this post


Link to post
Share on other sites
Valuater

how is the "section" selected by you or is there just one or ??

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Nahuel

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?

Share this post


Link to post
Share on other sites
FireLord

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]

Share this post


Link to post
Share on other sites
FireLord

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]

Share this post


Link to post
Share on other sites
Nahuel

1 section + 1 key = IniRead()

:P

Share this post


Link to post
Share on other sites
FireLord

1 section + 1 key = IniRead()

:P

You mentioned that already but it didn't work. What about StringInStr?


[center]See the Helpfile[/center]
While Alive()
	 DrinkWine();
}
[center][/center]

Share this post


Link to post
Share on other sites
Nahuel

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.

Share this post


Link to post
Share on other sites
FireLord

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]

Share this post


Link to post
Share on other sites
FireLord

...anyone?


[center]See the Helpfile[/center]
While Alive()
	 DrinkWine();
}
[center][/center]

Share this post


Link to post
Share on other sites
WaterBender

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.

Share this post


Link to post
Share on other sites
Bowmore

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

Share this post


Link to post
Share on other sites
FireLord

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]

Share this post


Link to post
Share on other sites
FireLord

Never mind my previous post. It's working.

Thank you very much. :P


[center]See the Helpfile[/center]
While Alive()
	 DrinkWine();
}
[center][/center]

Share this post


Link to post
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
Sign in to follow this  

×