Jump to content

Script iniWrite problem


shyron
 Share

Recommended Posts

I want to Choose e.g. MSN.exe, that works fine, but my problem is, when starting the script the 2. time I'd have to choose the path again even if it would be the same. How could i change that?(By saving yea, well heres my try)

If iniRead ("config", "Config", "msn", "") = "" Then
 FileOpenDialog ( "msn", "C:/", ".exe (*.*)" ,"" , "msn")
$sbot = iniWrite ("config", "config", "msn", "msn")
else 
 iniRead ("config", "Config", "msn", "") = $msn
EndIf
Link to comment
Share on other sites

It will depend on how you want to integrate it with the rest of your code. Pay attention to what you get in the way of returns from IniRead... I'll throw something together as an example for you in a few.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Cool... here is my example anyway:

#include <GUIConstantsEx.au3>

Local $msg , $iniPath = @ScriptDir & "\settings.ini"
GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered

$combo=GUICtrlCreateCombo("AOL", 10, 10) ; create first item
GUICtrlSetData($combo, "Google|MSN", "Google") ; add other item snd set a new default
GUISetState()

; grab the settings from the ini file, or make it if it is the first time
If FileExists($iniPath) Then
    $provider=IniRead($iniPath,"Settings","Provider","MSN")
    GUICtrlSetData($combo,$provider)
Else
    IniWrite($iniPath,"Settings","Provider","MSN")
EndIf
; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

; write the current setting to the ini file
IniWrite($iniPath,"Settings","Provider",GUICtrlRead ($combo))

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

$ini = @ScriptDir & "\config.ini" ; path from script default directory to the config.ini
IniReadSection($ini, "Config") ; try to read the Config section
If @error Then ; section doesn't exist so create it
    IniWriteSection($ini, "Config", "config=0") ; write the section but leave the path set to 0 so it can be set later.
EndIf
If IniRead($ini,"Config","config","") <> 0 Then ; if the script doesn't see 0 then you can move onward
    ;Input what you want to do if everything is OK with the ini file here.
Else
    Local $fOpen = FileOpenDialog("msn","C:\",".exe (*.*)","","msn") ; open the msn.exe file (prompt for dialog)
    IniWrite($ini,"Config","config",$fOpen) ; write the full path the msn.exe file here and use it going forward.
EndIf
Global $msn = IniRead($ini,"Config","config","")
MsgBox(0,"Reading .ini","My msn var is set to " & $msn)

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...