Sign in to follow this  
Followers 0
rinaldm

ini file update

8 posts in this topic

i want to check if a key in an ini file has a certain value if it is i need to change it , if the key doesn't exist in need to write some new entries to the ini file.

here is the code i have so far but all it does is write the entry after the then statement and skips everything else

If IniRead("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "class") = "class" Then

Iniwrite("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "trainer")

Else

IniWrite("C:\WINNT\class.ini", "Databases", "New Class", "")

IniWrite("C:\WINNT\class.ini", "Databases", "New Trainer", "")

EndIf

any help would be appreciated

Share this post


Link to post
Share on other sites



Wow, could you please reword your question? I have no idea what you're trying to say.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ok i'm trying to check a key in an ini file to see if it is set to class if it is i need to change it to trainer, if the key is set to trainer i dont need to do anything. if the key is not there i need to add it

Edited by rinaldm

Share this post


Link to post
Share on other sites

First time you run it the ini contains:

[New Trainer]DatabaseName=trainer

Second and subsequent times it contains:

[New Trainer]DatabaseName=trainer

[Databases]

New Class=

New Trainer=

So thats exactly what you have coded in the script.

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

ok what i want it to do is this

IF [New Trainer]

DatabaseName=Class Then

change to [New Trainer]

DatabaseName=Trainer

else

add [Databases]

New Class=

New Trainer=

Share this post


Link to post
Share on other sites

i  want to check if a key in an ini file has a certain value if it is i need to change it , if the key doesn't exist in need to write some new entries to the ini file.

here is the code i have so far but all it does is write the entry after the then statement and skips everything else

If IniRead("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "class") = "class" Then

  Iniwrite("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "trainer")

Else

  IniWrite("C:\WINNT\class.ini", "Databases", "New Class", "")

  IniWrite("C:\WINNT\class.ini", "Databases", "New Trainer", "")

EndIf

any help would be appreciated

I'm not quite getting it myself but here's a basic idea

$var=iniread("path\my.ini,"Section","key","DefaultValue")

;now if it's does not exist it will give the defaultvalue. If it does exist but is blank it will be empty so

if $var="defalutvalue" or $var="" then

iniwrite("path\my.ini","Section","key","MyNewValue")

endif

Hope that helped

Rick


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

Like this ? :

If IniRead("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "") = "class" Then
   Iniwrite("C:\WINNT\class.ini", "New Trainer", "DatabaseName", "trainer")
Else
   IniWrite("C:\WINNT\class.ini", "Databases", "New Class", "")
   IniWrite("C:\WINNT\class.ini", "Databases", "New Trainer", "")
EndIf

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Got it working thanks for the help JdeB

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  
Followers 0