Sign in to follow this  
Followers 0
PrinsBertil

Help with iniwrite/iniread

6 posts in this topic

Hi

I have just started using AutoIt as a program and I have started to write a script to use.

My computer knowledge is avarage, I work as a sea captain and last time was makin a program was when c64 was hot (about 20 years ago)

And I remember it something like:

10 write FUCK

20 goto 10

The thing is that I want some values to stay for next time I open up the script and I figured that using the writeini and readini would give me the best results.

Iäve looked and passed the AutoIt 1-2-3 and checked the forums and other scripts for answers, but havnt really figured this one out since it writes an Ini file but the values won't change for me.

I hope that someone can help me out and that someone can explain it simple.

What I'va manage to do is to write a GUI but I don't know how to get all functions to run perfectly

#include <GuiConstants.au3>

; GUI
    GuiCreate("Flash", 486, 528, -1, -1, $WS_EX_TOPMOST)
    GuiSetIcon(@SystemDir & "\mspaint.exe", 0)
    $title = "Flash"

    
; INPUT

   $Latency = IniRead ("Settings.ini", "Latency", "Latency", "100") 
   $ResolutionX = IniRead ("Settings.ini", "Resolution", "ResolutionX", "800") 
   $ResolutionY = IniRead ("Settings.ini", "Resolution", "ResolutionY", "600") 

test()

Func test()

    GuiCtrlCreateLabel("Latency", 260, 405)
    $Latency = GuiCtrlCreateInput("" & $Latency, 260, 420, 40, 20) 
    GUICtrlSetLimit($Latency,4)
    If $Latency <> "" then 
         IniWrite("Settings.ini", "Latency", "Latency", " " & $Latency) 
    Else 
         $Latency = 100 
         ErrorMsg() 
         IniWrite("Settings.ini", "Latency", "Latency", " 100") 
    endif 
    
    GuiCtrlCreateLabel("Resolution", 260, 445)
    $ResolutionX = GuiCtrlCreateInput("" & $ResolutionX, 260, 460, 40, 20)
    GUICtrlSetLimit($ResolutionX,4)
    If $ResolutionX >= 1 AND $ResolutionX <= 1600 then 
         IniWrite("Settings.ini", "Resolution", "ResolutionX", " " & $ResolutionX) 
    Else 
         ErrorMsg() 
         IniWrite("Settings.ini", "Resolution", "ResolutionX", " 800") 
    endIf
    
    GuiCtrlCreateLabel("X", 302, 463)
    $ResolutionY  = GuiCtrlCreateInput("" & $ResolutionY, 310, 460, 40, 20)
    GUICtrlSetLimit($ResolutionY,4)
      If $ResolutionY >= 1 AND $ResolutionY <= 1200 then 
         IniWrite("Settings.ini", "Resolution", "ResolutionY", " " & $ResolutionY) 
      Else 
         ErrorMsg() 
         IniWrite("Settings.ini", "Resolution", "ResolutionY", " 600") 
     endIf
endFunc

GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

10 write FUCK

... isn't a great approach when asking for help

this will not work

$Latency = IniRead ("Setti.....

$Latency = GuiCtrlCreateInput("" & $Latency, .....

If $Latency <> "" then

$Latency can not be used in all of these locations at the same time, use different names

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Hi

I have just started using AutoIt as a program and I have started to write a script to use.

My computer knowledge is avarage, I work as a sea captain and last time was makin a program was when c64 was hot (about 20 years ago)

And I remember it something like:

10 write FUCK

20 goto 10

The thing is that I want some values to stay for next time I open up the script and I figured that using the writeini and readini would give me the best results.

Iäve looked and passed the AutoIt 1-2-3 and checked the forums and other scripts for answers, but havnt really figured this one out since it writes an Ini file but the values won't change for me.

I hope that someone can help me out and that someone can explain it simple.

What I'va manage to do is to write a GUI but I don't know how to get all functions to run perfectly

#include <GuiConstants.au3>

; GUI
    GuiCreate("Flash", 486, 528, -1, -1, $WS_EX_TOPMOST)
    GuiSetIcon(@SystemDir & "\mspaint.exe", 0)
    $title = "Flash"

    
; INPUT

   $Latency = IniRead ("Settings.ini", "Latency", "Latency", "100") 
   $ResolutionX = IniRead ("Settings.ini", "Resolution", "ResolutionX", "800") 
   $ResolutionY = IniRead ("Settings.ini", "Resolution", "ResolutionY", "600") 

test()

Func test()

    GuiCtrlCreateLabel("Latency", 260, 405)
    $Latency = GuiCtrlCreateInput("" & $Latency, 260, 420, 40, 20) 
    GUICtrlSetLimit($Latency,4)
    If $Latency <> "" then 
         IniWrite("Settings.ini", "Latency", "Latency", " " & $Latency) 
    Else 
         $Latency = 100 
         ErrorMsg() 
         IniWrite("Settings.ini", "Latency", "Latency", " 100") 
    endif 
    
    GuiCtrlCreateLabel("Resolution", 260, 445)
    $ResolutionX = GuiCtrlCreateInput("" & $ResolutionX, 260, 460, 40, 20)
    GUICtrlSetLimit($ResolutionX,4)
    If $ResolutionX >= 1 AND $ResolutionX <= 1600 then 
         IniWrite("Settings.ini", "Resolution", "ResolutionX", " " & $ResolutionX) 
    Else 
         ErrorMsg() 
         IniWrite("Settings.ini", "Resolution", "ResolutionX", " 800") 
    endIf
    
    GuiCtrlCreateLabel("X", 302, 463)
    $ResolutionY  = GuiCtrlCreateInput("" & $ResolutionY, 310, 460, 40, 20)
    GUICtrlSetLimit($ResolutionY,4)
      If $ResolutionY >= 1 AND $ResolutionY <= 1200 then 
         IniWrite("Settings.ini", "Resolution", "ResolutionY", " " & $ResolutionY) 
      Else 
         ErrorMsg() 
         IniWrite("Settings.ini", "Resolution", "ResolutionY", " 600") 
     endIf
endFunc

GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd
Something like this is a good start: Mind you it's very pragmatic :D

#include <GuiConstants.au3>
; GUI
    $MyGUI = GuiCreate("Flash", 533, 634, -1, -1, $WS_EX_TOPMOST)
    GuiSetIcon(@SystemDir & "\mspaint.exe", 0)
    $title = "Flash"
; INPUT
    $INIFile = @ScriptDir&"\Settings.ini"
    if FileExists($INIFile) Then
        $Latency = IniRead ($INIFile, "Latency", "Latency", "100")
        $ResolutionX = IniRead ($INIFile, "Resolution", "ResolutionX", "800")
        $ResolutionY = IniRead ($INIFile, "Resolution", "ResolutionY", "600")
    Else
        $Latency = "100"
        $ResolutionX = "800"
        $ResolutionY = "600"
    EndIf

; Build Controls
    GuiCtrlCreateLabel("Latency", 260, 405)
    $LatencyChange = GuiCtrlCreateInput("", 260, 420, 40, 20)
    GUICtrlSetLimit($Latency,4)

    GuiCtrlCreateLabel("Resolution", 260, 445)
    $ResolutionXChange = GuiCtrlCreateInput("", 260, 460, 40, 20)
    GUICtrlSetLimit($ResolutionX,4)

    GuiCtrlCreateLabel("X", 302, 463)
    $ResolutionYChange  = GuiCtrlCreateInput("", 310, 460, 40, 20)
    GUICtrlSetLimit($ResolutionY,4)

    $ChangeData = GuiCtrlCreateButton("Change", 360, 460, 80, 20)

; Set Control Data
    guictrlsetdata($LatencyChange, $Latency)
    guictrlsetdata($ResolutionXChange, $ResolutionX)
    guictrlsetdata($ResolutionYChange, $ResolutionY)
    
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            call("SetData")
            Exit
        
    case $ChangeData
            call("SetData")
                guictrlsetdata($LatencyChange, $Latency)
                guictrlsetdata($ResolutionXChange, $ResolutionX)
                guictrlsetdata($ResolutionYChange, $ResolutionY)
    EndSwitch
WEnd

Func SetData()
$Latency = Guictrlread($LatencyChange)
    if $Latency = "" then $Latency = "100"

$ResolutionX = guictrlread($ResolutionXChange)
    if $ResolutionX = "" then $ResolutionX = "800"

$ResolutionY = GUICtrlRead($ResolutionYChange)
    if $ResolutionY = "" then $ResolutionY = "600"

IniWrite($INIFile, "Latency", "Latency", $Latency)
IniWrite($INIFile, "Resolution", "ResolutionX", $ResolutionX)
IniWrite($INIFile, "Resolution", "ResolutionY", $ResolutionY)
EndFunc

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

thanks for the fast reply.

yes my example of my knowledge from c64 might have been abit inapropriate, I agree.

I was 7 at the time and at that age it was ver amusing, now when I think back on that time I lauge at myself for being easily amused as a child.

Anyway, I realized my mistake.

I did watch to much on another script where they use InputBox's instead and that way the scripts run and halt for next question. it isn't made as a GUI

e.g.

#include <GuiConstants.au3>

    $title = "Flash"
    

HotKeySet("{Pause}", "ExitScript")

Func ExitScript()
    Exit
EndFunc 
    
; INPUT

   $Latency = IniRead ("Settings.ini", "Latency", "Latency", "100") 
   $ResolutionX = IniRead ("Settings.ini", "Resolution", "ResolutionX", "800") 
   $ResolutionY = IniRead ("Settings.ini", "Resolution", "ResolutionY", "600") 

test()

Func test()

    $Latency = InputBox($title, "bla" ,"" & $Latency, "", 251, 244) 
    If $Latency <> "" then 
         IniWrite("Settings.ini", "Latency", "Latency", " " & $Latency) 
    Else 
         $Latency = 100 
         ErrorMsg() 
         IniWrite("Settings.ini", "Latency", "Latency", " 100") 
    endif 
    

    
    $ResolutionX = InputBox($title, "bla", "" & $ResolutionX, "", 251, 244)
    If $ResolutionX >= 1 AND $ResolutionX <= 1600 then 
         IniWrite("Settings.ini", "Resolution", "ResolutionX", " " & $ResolutionX) 
    Else 
         ErrorMsg() 
         IniWrite("Settings.ini", "Resolution", "ResolutionX", " 800") 
    endIf
    
    $ResolutionY  = InputBox($title, "bla", "" & $ResolutionY, "", 251, 244)
      If $ResolutionY >= 1 AND $ResolutionY <= 1200 then 
         IniWrite("Settings.ini", "Resolution", "ResolutionY", " " & $ResolutionY) 
      Else 
         ErrorMsg() 
         IniWrite("Settings.ini", "Resolution", "ResolutionY", " 600") 
     endIf
endFunc

GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Thank you very much zackrspv it feels like your help solved alot :D

Edited by PrinsBertil

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

thanks for the fast reply.

yes my example of my knowledge from c64 might have been abit inapropriate, I agree.

I was 7 at the time and at that age it was ver amusing, now when I think back on that time I lauge at myself for being easily amused as a child.

Anyway, I realized my mistake.

I did watch to much on another script where they use InputBox's instead and that way the scripts run and halt for next question. it isn't made as a GUI

e.g.

#include <GuiConstants.au3>

    $title = "Flash"
    

HotKeySet("{Pause}", "ExitScript")

Func ExitScript()
    Exit
EndFunc 
    
; INPUT

   $Latency = IniRead ("Settings.ini", "Latency", "Latency", "100") 
   $ResolutionX = IniRead ("Settings.ini", "Resolution", "ResolutionX", "800") 
   $ResolutionY = IniRead ("Settings.ini", "Resolution", "ResolutionY", "600") 

test()

Func test()

    $Latency = InputBox($title, "bla" ,"" & $Latency, "", 251, 244) 
    If $Latency <> "" then 
         IniWrite("Settings.ini", "Latency", "Latency", " " & $Latency) 
    Else 
         $Latency = 100 
         ErrorMsg() 
         IniWrite("Settings.ini", "Latency", "Latency", " 100") 
    endif 
    

    
    $ResolutionX = InputBox($title, "bla", "" & $ResolutionX, "", 251, 244)
    If $ResolutionX >= 1 AND $ResolutionX <= 1600 then 
         IniWrite("Settings.ini", "Resolution", "ResolutionX", " " & $ResolutionX) 
    Else 
         ErrorMsg() 
         IniWrite("Settings.ini", "Resolution", "ResolutionX", " 800") 
    endIf
    
    $ResolutionY  = InputBox($title, "bla", "" & $ResolutionY, "", 251, 244)
      If $ResolutionY >= 1 AND $ResolutionY <= 1200 then 
         IniWrite("Settings.ini", "Resolution", "ResolutionY", " " & $ResolutionY) 
      Else 
         ErrorMsg() 
         IniWrite("Settings.ini", "Resolution", "ResolutionY", " 600") 
     endIf
endFunc

GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Thank you very much zackrspv it feels like your help solved alot :D

This is more of an observation from someone who came from the old days of 8086 'programming' if you will. In the olden days, prompts were the mainstays of computing; if we wanted information, we would repeatedly prompt the user for that information and continue on. While the process hasn't changed that much, the attitudes towards programming have. Instead of relying on information from the CLIENT, we create defaults, or starting values at which the client can change. The days of preferences, settings and configurations is by far the most preferred method to date for programmatic information.

Your script, while valid in what it does, in my opinion, should be revamped to be a single dialog box asking for those 3 values and then moving on. If the configuration file doesn't exist, than it uses the default values and moves on, and if the client wishes to change that information, they can launch the configuration file to change those settings as desired.

In todays day and age of 'fast food', 'fast cars', and user friendly programs, constant prompts, like in the script outlined above, can be.....negative when released.

Now, i'm not calling you out here, i'm just making an observation. I feel it would best benefit you to rethink, somewhat, your style of programming to be more.....friendly, towards the person who will be using the script, even if it's yourself. Cut out most of the work and continue on to the meat of the 'program' or 'script' that you are trying to accomplish.

Yes, input boxes are great, and quite useful; but which would you rather have: 3 prompts, back to back, asking for information, or one single page that comes up where you can fill in the information? The latter, in my opinion, would seem to take more advantage of the language that Auto.IT offers.

--done.

/me waits for the flaming to begin haha. Voicing opinions in an open forum, is, suffice it to say, very dangerous.

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

Resurecting this subject again for some quick help (I hope)

How can I make the "change" button start another script in the same folder and close itself (the GUI "flash")?

My guess is that it is GUIDelete() that would be my best bet of use.

But I am very unsure of how to implement this

The other script that is in the same folder is reading the ini file for settings. file name Script.au3

I assume that I can use the same function to call this GUI when the other script terminates.

(or atleast almost the same) the other is a script with no GUI and is ended while Pressing Ctrl and PAUSE something like

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("^{PAUSE}", "request_end");Ctrl+PAUSE

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

func request_end() 
    $MB_YESNO = 4 
    $MB_YES = 6 

    if MsgBox($MB_YESNO, $title, "End script?") == $MB_YES then 
        Exit 
    endif 
endfunc

will get me the dialog box YES and NO. And YES will terminate the script.

As the script terminates I want it to start the GUI file again.

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