Sign in to follow this  
Followers 0
DemeGeek

Not Reading INI files correctly OR logic errors

4 posts in this topic

Hello,

I am currently having problems with a program that I am making with autoit, I have a GUI window that has several buttons on it and one of those buttons I want to disable when there is no proxy settings in the settings file, which happens to be an ini.

The GUI part I am fine with, but I am having troubles with the INI reading part. No matter what I do, the IniRead() function does not appear to actually read the file but just defaults to TRUE. Perhaps my code can help explain:

$proxy = False
If IniRead("settings.ini", "proxy", "proxyhost", False) Then
$proxy = True
MsgBox(0, "Test", "found proxyhost")
Else
$proxy = False
EndIf
If IniRead("settings.ini", "proxy", "proxyport", False) Then
$proxy = True
MsgBox(0, "Test", "found proxyport")
Else
$proxy = False
EndIf
MsgBox(0, "Test", $proxy)

and the settings.ini file (when it is filled):

[proxy]
proxyhost=localhost
proxyport=6795

Is there any glaring flaws in my code? I cannot seem to figure it out, currently all the MsgBox()s trigger even when settings.ini is empty... any thoughts?

Thanks for reading (and posting!)

Share this post


Link to post
Share on other sites



IniRead reads a string value.

Try this:

If "abc" Then ConsoleWrite("Yes!" & @LF)
If "False" Then ConsoleWrite("Yes too!" & @LF)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

if what jchds is true then you'll have to just to assign a certain String value to a non existing proxy setting.

For example you put

[proxy]

proxyhost="n/a"

proxyport="n/a"

If IniRead("settings.ini", "proxy", "proxyhost", "n/a") Then

Just a quick thought though, never worked with .ini files...


I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites

Thanks to Jchd, I now have the answer.

Instead of having a default value I just made it so that it returns nothing if it doesn't get anything from the INI so that it won't return false-positives:

$proxy = False
If IniRead("settings.ini", "proxy", "proxyhost", "")  Then
$proxy = True
EndIf
If IniRead("settings.ini", "proxy", "proxyport", "") Then
$proxy = True
EndIf

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