Sign in to follow this  
Followers 0
CyberFunk Productions

Ini Reading

6 posts in this topic

ok what happens here is func B() looks to see is it can read a line in the ini, if it can't it calls shortC() where info is collected and the ini is written. Now when i access func B() again is should fall through the if statement because it should returns false and should follow the Else statement and read the ini's. instead it goes through the If statement again untill i restart the program,then it will work properly. It should reconize that there is a line written. how do i make it so i don't have to restart the program for it to work?

Func ShortC()                                                                  
   $Path = FileSelectFolder("Choose a file", "", 0)                             
   $File = FileOpenDialog("File EXE", "C:\Program Files\", "Files (*.exe)", 1) 
   Sleep(500)
   IniWrite( @ScriptDir & "\Keys.ini\", $Key, "F6P", $Path)                        
   IniWrite( @ScriptDir & "\Keys.ini\", $Key, "F6F", $File)
EndFunc



Func B()
   $search =  IniRead("Keys.ini", "B.ini", "F6F", "default")     
   IF $search = "default" Then                         
      $Answer = MsgBox(4, "Not configured!", "Would you like to configure this key?")   
      If $Answer = 6 Then                        
         $Key = "B.ini"
         Call ( "ShortC" ) 
      EndIf
   Else
      $File = IniRead ( ".\Keys.ini", "B.ini", "F6F", "default" )   
      $Path = IniRead ( ".\Keys.ini", "B.ini", "F6P", "default" )
      Run($File, $Path, @SW_MAXIMIZE)
   EndIf
EndFunc

Share this post


Link to post
Share on other sites



You will have to call B() again. An If statement doesn't fall-through. If it is true, then the stuff after then is execute, otherwise, the stuff in the Else clause will be executed.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

i know that, when i call B() after i've written the ini it will ask me to configure again until i exit the program and start it again, then it will work. I want to avoid doing that. Its like the $Search = IniRead... is not noticing that there is already a line in the ini file.

ok, compile this script and you'll see what i mean:(make sure to put the compiled script in a folder!)

HotKeySet("^!a", "A")

Global $Key

While 1
   Sleep(100)
WEnd

Func ShortC()                                                                  
   $Path = FileSelectFolder("Choose a file", "", 0)                            
   $File = FileOpenDialog("File EXE", "C:\Program Files\", "Files (*.exe)", 1) 
   Sleep(500)
   IniWrite( @ScriptDir & "\Keys.ini\", $Key, "F6P", $Path)                     
   IniWrite( @ScriptDir & "\Keys.ini\", $Key, "F6F", $File)
EndFunc


Func A()
   $search =  IniRead( "Keys.ini", "A.ini", "F6F", "default")         
   IF $search = "default" Then                 
      $Answer = MsgBox(4, "Not configured!", "Would you like to configure this key?")   
      If $Answer = 6 Then                        
         $Key = "A.ini"
         Call ( "ShortC" ) 
      EndIf
   Else 
      $File = IniRead ( ".\Keys.ini", "A.ini", "F6F", "default" )       
      $Path = IniRead ( ".\Keys.ini", "A.ini", "F6P", "default" )
      MsgBox(0, "Path", $Path)
      MsgBox(0, "File", $File) 
   EndIf
EndFunc

Just run it, press ctrl + alt + a, then pick a folder and then pick a file. then press ctrl + alt + a again and see if the message boxes come up.

Edited by CyberFunk Productions

Share this post


Link to post
Share on other sites

look at above^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Share this post


Link to post
Share on other sites

I see lots of issues surrounding the name of the INI file. First there is:

IniWrite( @ScriptDir & "\Keys.ini\", $Key, "F6P", $Path)

But because of the trailing slash, that's just a path, not a file.

Then there is this one:

$search =  IniRead( "Keys.ini", "A.ini", "F6F", "default")

That one is trying to read an INI in the current working directory (Which may or may not be the @ScriptDir; There are ways to change the working directory.

And then this:

$File = IniRead ( ".\Keys.ini", "A.ini", "F6F", "default" )

is effectively the same as the above.

I would recommend doing this:

$szIni = @ScriptDir & "\keys.ini"

Now use $szIni to read or write to the INI instead of hard-coding paths in there.

Share this post


Link to post
Share on other sites

oh wow thats awsome, your $szIni = @ScriptDir & "\keys.ini" idea worked great, thanx, that fixes a huge bug in my full program.

:D:huh2::)

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