Jump to content

save in inifile


Recommended Posts

here is a part of my code (the code is a little bit like human language)

While 1

if button1 is preesed then

IniWrite("log.ini", "section2", "key", "button1")

EndIf

if button2 is preesed then

IniWrite("log.ini", "section2", "key", "button2")

EndIf

Sleep(100)

WEnd

what i want is that the iniwrite saves the value of the button 1 and 2 together like

[section2]

key=button1 button2

thanks

Link to comment
Share on other sites

While 1
    if $msg = $button1 then 
        if IniRead("log.ini", "section2", "key", "") = "button2" Then
            IniWrite("log.ini", "section2", "key", "button1button2")
        ElseIf IniRead("log.ini", "section2", "key", "") = "button1button2" Then
            ;do whatever
        Else
            IniWrite("log.ini", "section2", "key", "button1")
        EndIf
    EndIf

    else if $msg = $button2 then 
        if IniRead("log.ini", "section2", "key", "") = "button1" Then
            IniWrite("log.ini", "section2", "key", "button1button2")
        ElseIf IniRead("log.ini", "section2", "key", "") = "button1button2" Then
            ;do whatever
        Else
            IniWrite("log.ini", "section2", "key", "button2")
        EndIf
    EndIf
    Sleep(100)
WEnd

I guess? :)

I fail to see how this is useful. Explain?

Edited by Bomi
Link to comment
Share on other sites

While 1
    if $msg = $button1 then 
        if IniRead("log.ini", "section2", "key", "") = "button2" Then
            IniWrite("log.ini", "section2", "key", "button1button2")
        ElseIf IniRead("log.ini", "section2", "key", "") = "button1button2" Then
            ;do whatever
        Else
            IniWrite("log.ini", "section2", "key", "button1")
        EndIf
    EndIf

    else if $msg = $button2 then 
        if IniRead("log.ini", "section2", "key", "") = "button1" Then
            IniWrite("log.ini", "section2", "key", "button1button2")
        ElseIf IniRead("log.ini", "section2", "key", "") = "button1button2" Then
            ;do whatever
        Else
            IniWrite("log.ini", "section2", "key", "button2")
        EndIf
    EndIf
    Sleep(100)
WEnd

I guess? :)

I fail to see how this is useful. Explain?

thanks for the answer but, what i mean is that my program has other things instead of buttons and when i try to save things into an ini it just saves them by sections, so what i want to know is how to put things in the same section, i know your way is an answer but it will take me a lot of time to put all the combinations that my program can follow

for the other answer, im a teacher and i want to initiate the creativity of my students, so my program has lots of answers, buttons,etc to use and to get to a final answer, hope u know how, to do it by an easier way

Link to comment
Share on other sites

;Quizzzz
#include <GUIConstants.au3>

$QuizzGui = GUICreate("Quiz GUI", 250, 500)
$Question = GUICtrlCreateLabel("Select the four first letter in the alphabet,\n but not the third one", 10, 10)
dim $Box [6] ;Box[0] isnt used because of ini read/write works best with this blank (used for other values)
$Box[1] = GUICtrlCreateCheckbox("A", 10, 40) ;correct
$Box[2] = GUICtrlCreateCheckbox("B", 10, 70) ;correct
$Box[3] = GUICtrlCreateCheckbox("C", 10, 100) ;incorrect
$Box[4] = GUICtrlCreateCheckbox("D", 10, 130) ;correct
$Box[5] = GUICtrlCreateCheckbox("E", 10, 160) ;incorrect
$Submit = GUICtrlCreateButton("Submit", 10, 190, 240)
GUISetState()

Func SubmitFunction()
    Dim $BoxArray[6][2] ;[6] answers [2] data types (key/value)
    Local $i = 1
    While $i < 6
        $BoxArray[$i][0] = "Checkbox_"&$i
        $BoxArray[$i][1] = GUICtrlRead($Box[$i])
        $i += 1
    WEnd
    IniWriteSection("Save.ini", "AnswerQuestion1", $BoxArray)
    MsgBox(0, "Answers Submited", "Answers have been stored!")
    $IniReadTmp = IniReadSection("Save.ini", "AnswerQuestion1") ;Reads the whole section into a 2d array. E.g. $Array[1][1]. Where [0][0] is the number of keys/values
    Local $i = 1
    $sTmpOut = ""
    Do ;/Loop
        $sTmpOut &= $IniReadTmp[$i][0]&" = "&$IniReadTmp[$i][1]&@CRLF ; $s &= "abc" is the same as $s = $s & "abc". @CRLF is linebreak
        $i += 1
    Until $i > $IniReadTmp[0][0] ; Number of keys/values
    MsgBox(0, "Ini", $sTmpOut)
    Exit
EndFunc

While 1
    $msg  = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    ElseIf $msg = $Submit Then
        SubmitFunction()
    EndIf
WEndoÝ÷ Ù¬º[l{ayú%"âéÚè§Ç¶*'Öl{

On the other hand will result in:

[section1]

myKey = sometihin

myKey2 = something completly different

Regards,

Eivin

Link to comment
Share on other sites

;Quizzzz
#include <GUIConstants.au3>

$QuizzGui = GUICreate("Quiz GUI", 250, 500)
$Question = GUICtrlCreateLabel("Select the four first letter in the alphabet,\n but not the third one", 10, 10)
dim $Box [6] ;Box[0] isnt used because of ini read/write works best with this blank (used for other values)
$Box[1] = GUICtrlCreateCheckbox("A", 10, 40) ;correct
$Box[2] = GUICtrlCreateCheckbox("B", 10, 70) ;correct
$Box[3] = GUICtrlCreateCheckbox("C", 10, 100) ;incorrect
$Box[4] = GUICtrlCreateCheckbox("D", 10, 130) ;correct
$Box[5] = GUICtrlCreateCheckbox("E", 10, 160) ;incorrect
$Submit = GUICtrlCreateButton("Submit", 10, 190, 240)
GUISetState()

Func SubmitFunction()
    Dim $BoxArray[6][2] ;[6] answers [2] data types (key/value)
    Local $i = 1
    While $i < 6
        $BoxArray[$i][0] = "Checkbox_"&$i
        $BoxArray[$i][1] = GUICtrlRead($Box[$i])
        $i += 1
    WEnd
    IniWriteSection("Save.ini", "AnswerQuestion1", $BoxArray)
    MsgBox(0, "Answers Submited", "Answers have been stored!")
    $IniReadTmp = IniReadSection("Save.ini", "AnswerQuestion1") ;Reads the whole section into a 2d array. E.g. $Array[1][1]. Where [0][0] is the number of keys/values
    Local $i = 1
    $sTmpOut = ""
    Do ;/Loop
        $sTmpOut &= $IniReadTmp[$i][0]&" = "&$IniReadTmp[$i][1]&@CRLF ; $s &= "abc" is the same as $s = $s & "abc". @CRLF is linebreak
        $i += 1
    Until $i > $IniReadTmp[0][0] ; Number of keys/values
    MsgBox(0, "Ini", $sTmpOut)
    Exit
EndFunc

While 1
    $msg  = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    ElseIf $msg = $Submit Then
        SubmitFunction()
    EndIf
WEndoÝ÷ Ù¬º[l{ayú%"âéÚè§Ç¶*'Öl{

On the other hand will result in:

[section1]

myKey = sometihin

myKey2 = something completly different

Regards,

Eivin

hello, its almost like it but i want the answers to be one next to the other something like this

[section1]

RaulKey = octagonal triangle, pentagonal, B, A, down from the tree, etc

but my program has to many buttons and letters so i cant use the first answer i got from this post it will took me forever to make all of the combinations

thanks for the answer, but if u please can help me to make this part of the program. thanks

Link to comment
Share on other sites

  • Moderators

Like a dog chasing its tail. It's obvious you can't explain it well enough for others to understand. Yet you continue to repeat yourself.

Remember, no one here is a mind reader, and with the little example you've shown helps no one to know truly what you want to do.

Here's a suggestion.

1. Post your script (working or not so it can be edited and played with to figure out what you want).

2. Show (hard coded if need be) in the GUI how you would like it to appear.

Otherwise, you are wasting others time (as the posters above did take time to try and understand what you wanted and tried to make it as they understood it).

P.S. If you work is secret, then at least take as much time as the others did and create a recreation script that demonstrates the issue you are having and the output you actually would like.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Like a dog chasing its tail. It's obvious you can't explain it well enough for others to understand. Yet you continue to repeat yourself.

Remember, no one here is a mind reader, and with the little example you've shown helps no one to know truly what you want to do.

Here's a suggestion.

1. Post your script (working or not so it can be edited and played with to figure out what you want).

2. Show (hard coded if need be) in the GUI how you would like it to appear.

Otherwise, you are wasting others time (as the posters above did take time to try and understand what you wanted and tried to make it as they understood it).

P.S. If you work is secret, then at least take as much time as the others did and create a recreation script that demonstrates the issue you are having and the output you actually would like.

hello, well if it cant be understandable then ill try to find it by my way, but i really tried to explain it, my program is not finished at all, but when i finish it at 100% ill post it here, the question of my programs are almost all of them mathematically and others to think a lot, i think you guys will enjoy the questions .

ill try to make that recreation cause i want nobody to see my program until its done. THANKS FOR THE HELP GUYS

Link to comment
Share on other sites

;Quizzz Vers 2.0
#include <GUIConstants.au3>

$QuizzGui = GUICreate("Quiz GUI", 250, 500)
$Question = GUICtrlCreateLabel("RawrRawr", 10, 10)

; Different types of GUI stuff:
$button = GUICtrlCreateButton( "This is a button | o", 10, 10, 240, 22 )
$checkboxTxt = "This is a checkbox" ;This is used for submission purposes
$checkbox = GUICtrlCreateCheckbox( $checkboxTxt, 10, 40 )
$input = GUICtrlCreateInput( "Enter something", 10, 70, 200)
$inputOK = GUICtrlCreateButton( "ok", 210, 70, 30, 22 )

; +Submit Button
$Submit = GUICtrlCreateButton( "This is a submit button", 10, 100, 240, 22 )
GUISetState() ;Showtime

;Funky
Func btn_toggle($hBtn, $sTrue, $sFalse)
    If GUICtrlRead($hBtn) = $sTrue Then
        GUICtrlSetData($hBtn, $sFalse)
    Else
        GUICtrlSetData($hBtn, $sTrue)
    EndIf
EndFunc

Func input_toggle($hInput, $hBtn, $sTrue, $sFalse)
    If GUICtrlRead($hBtn) = $sTrue Then
        GUICtrlSetData($hBtn, $sFalse)
        GUICtrlSetState( $hInput, $GUI_DISABLE )
    Else
        GUICtrlSetData($hBtn, $sTrue)
        GUICtrlSetState( $hInput, $GUI_ENABLE )
    EndIf
EndFunc



Func SubmitFunction()
    local $iniString
    ;Button
    If GUICtrlRead($button) = "This is a button | x" Then ; 1 is hooked, 4 is not
        If Not $iniString = "" Then $iniString &= ", "
        $iniString &= GUICtrlRead($button)
    EndIf
#cs ;Alternatly, save the button text as is. clicked or not
    If Not $iniString = "" Then $iniString &= ", "
    $iniString &= GUICtrlRead($button)
#CE

    ;Checkbox
    If GUICtrlRead($checkbox) = 1 Then ; 1 is hooked, 4 is not
        If Not $iniString = "" Then $iniString &= ", "
        $iniString &= $checkboxTxt
    EndIf
    ;Input
    If GUICtrlRead($inputOK) = "edit" Then ;Means 'ok' was pressed
        If Not $iniString = "" Then $iniString &= ", "
        $iniString &= GUICtrlRead($input)
    EndIf
    
    ;Note: the above could easily be converted into a function
    
    IniWrite("save.ini", "section z", "Bomi (An)swe(a)rs", $iniString)
    MsgBox(0, "RAWR", IniRead("save.ini", "section z", "Bomi (An)swe(a)rs", "Reading save.ini failed!"))
    Exit
EndFunc

While 1
    $msg  = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    ElseIf $msg = $button Then
        btn_toggle($button, "This is a button | o", "This is a button | x")
    ElseIf $msg = $inputOK Then
        input_toggle($input, $inputOK, "ok", "edit")
    ElseIf $msg = $Submit Then
        SubmitFunction()
    EndIf
WEnd

This was(/is?) a fun challenge.

Did i get it right this time?

Remember, no one here is a mind reader, and with the little example you've shown helps no one to know truly what you want to do.

I beg to differ. Although mind reading over distance can be quite difficult
Link to comment
Share on other sites

  • Moderators

I beg to differ. Although mind reading over distance can be quite difficult

The fact that you asked this question:

This was(/is?) a fun challenge.

Did i get it right this time?

Leaves you no room to beg to differ :D :D

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I surrender, you have destroyed my plan for world domination!

Alas, now I am forced to cross out mind reading from my list!

i though the moderator closed the post thats why i dint see it again, but a friend of mine told me to check my post to see the answer.

and i tell u, u almost read my mind, thanks for the code i never thought to do it that way, i now can continue my program i hope to end it soon

ill put some of the files that will be in my program here, but im not sure if u can post other stuff than software or code, so give me your email and ill send it to u, those r tricky games so u can train your mind and continue with the world domination

thanks

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...