Sign in to follow this  
Followers 0
Guest RNB

Iniwrite doesn't work after an opendialog box

4 posts in this topic

Hi everybody.

For my first post in this forum, i want to begin by a big THANK YOU to Jon & all for their work on AutoIt, an incredible tool. (A second thing is apologies for my english: if i read it quite easily, the writing is another thing).

Next, you have certainly guessed that i'm writing this message to ask a little help. here goes my gui problem:

It's an input box that display a file path read in an ini file. The user can change that path with an open dialog box (FileOpenDialog). If so, i update the input box with the new path (GuiWrite).

Until here, everything works.

But, when i want to rewrite the ini key with the new path through an "ok" button, nothing happens.

This is a lite version of the gui i'm trying to build, only with the control that put me into trouble.

#include "GUIConstants.au3"
Opt ("GUINotifyMode", 1)

$path_file = iniread ("INI_FILE", "SECTION", "KEY", "Error")

GUICreate ("MyApp", 300, 230)

$path_input = guisetcontrol ("input", $path_file, ...)
$path_button = guisetcontrol ("button", "Rep", ...)

$ok = guisetcontrol ("button", "OK", ...)
$cancel = guisetcontrol ("button", "Exit", ...)

guishow()

While 1

$n = GUIMsg ()

; CHOOSE A NEW PATH
if $n = $path_button then
       $choose_path = FileOpenDialog ("Rep", "", "executable (*.exe)" , 1)
       if $choose_path <> 1 then
       guiwrite ($path_input, 0, $choose_path)
        else
        endif
endif

; WRITE IN INI FILE
if $n = $ok then
      ; msgbox (0, "", $new_path_file)
       iniwrite ("INI_FILE", "SECTION", "KEY", guiread ($path_input))
       exit
endif

; EXIT
if $n = $cancel then
       exit
endif
if $n = -3 then
       exit
endif

wend

i wrote the same thing with a couple of other input boxes where the user have to type some infos if he wants to change it. The rewrite into the ini file with the "ok" button works perfectly. Only this input field, with the FileOpenDialog option, puts everything upside down.

The message box (commented in the script above) displays correctly the new path value, but it isn't write back into the ini file with the iniwrite command. If i type the file path myself (like in the other fields), it works, but when i use the open dialog box to acquire it, the rewriting fails.

Does somebody understands where i'm wrong?

Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have been learing alot of different things at once so much of this might not help you but maybe it will. ( or at least it ackknoleges that your alive until a more informed poster has time to reply.)

I once wrote and compiled an .exe for a chatterbot I was working on to add functionality to it. Upon executing the the .exe directly by double clicking the autoit created .exe the text file I scripted it to create and write to, appeared in the same directory as the scripted .exe I created ( no path was scripted into my created .exe) However when I used my chatterbot to call this .exe I noticed that the .txt file was written in the directory of the calling .exe (in this case the chatterbot's directory) Maybe this might help.

You also said that it works fine if you write the path yourself. Could you not assign that path to a to a UDF or variable. My lack of knowledge combined with the time of 6:14am could have easily caused me to totally misread your post but in reading mine maybe you will think of something that you may have missed on your own :ph34r:

Edited by Coffee

Share this post


Link to post
Share on other sites

@RNB:

I was trying to figure out what your trouble is, and I finally discovered that the ini file was being created in the same directory where the selected file is located instead of the original directory where the script is located.

It seems the script's working directory gets changed to the FileOpenDialog() directory that the selected file was in.

Try changing this line in your script

iniwrite ("INI_FILE", "SECTION", "KEY", guiread ($path_input))

to this.

iniwrite (@ScriptDir & "\INI_FILE", "SECTION", "KEY", guiread ($path_input))

Kendall

Share this post


Link to post
Share on other sites

I was trying to figure out what your trouble is, and I finally discovered that the ini file was being created in the same directory where the selected file is located instead of the original directory where the script is located.

That's exactly what was happening (seems similar to the chatterbot bug of Coffe). I should have noticed that.

Thanks Kendall, the @scriptdir stuff works perfectly :-).

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