Jump to content
Sign in to follow this  
alex OF DEATH

A Simple INI Read/Write

Recommended Posts

Code:

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Hotkeyset ( "^1",  "Send1" )
Hotkeyset ( "^2",  "Send2" )
Hotkeyset ( "^3",  "Send3" )
Hotkeyset ( "^4",  "Send4" )
Hotkeyset ( "^5",  "Send5" )

$MainGUI = GUICreate("Easy Char.", 470, 127, 287, 230)
$NewCtrl1 = GUICtrlCreateInput("" & IniRead ( "C;\var.ini", "[Characters]", "1", "10"), 63, 8, 161, 21)
$NewCtrl2 = GUICtrlCreateInput("" & IniRead ( "C;\var.ini", "[Characters]", "2", "10"), 63, 32, 161, 21)
$NewCtrl3 = GUICtrlCreateInput("" & IniRead ( "C;\var.ini", "[Characters]", "3", "10"), 63, 56, 161, 21)
$NewCtrl4 = GUICtrlCreateInput("" & IniRead ( "C;\var.ini", "[Characters]", "4", "10"), 63, 80, 161, 21)
$NewCtrl5 = GUICtrlCreateInput("" & IniRead ( "C;\var.ini", "[Characters]", "5", "10"), 63, 104, 161, 21)
$SaveButton = GUICtrlCreateButton("Save Current Characters", 224, 104, 121, 17, 0)
GUISetOnEvent ( $SaveButton, "SaveToIni" )
$Ctrl1Label = GUICtrlCreateLabel("Ctrl 1:", 4, 8, 28, 17)
$Ctrl2Label = GUICtrlCreateLabel("Ctrl 2:", 4, 32, 28, 17)
$Ctrl3Label = GUICtrlCreateLabel("Ctrl 3:", 4, 56, 28, 17)
$Ctrl4Label = GUICtrlCreateLabel("Ctrl 4:", 4, 80, 28, 17)
$Ctrl5Label = GUICtrlCreateLabel("Ctrl 5:", 4, 104, 28, 17)
$WhatToDo = GUICtrlCreateLabel("What to do:  Copy and a paste a character", 256, 8, 206, 17)
$WhatToD2 = GUICtrlCreateLabel("into the box and hit 'Save.' Then, hit CTRL", 256, 24, 204, 17)
$WhatToD3 = GUICtrlCreateLabel("+ the number specified, and the char-", 256, 40, 196, 17)
$WhatToD4 = GUICtrlCreateLabel("acter will be automatically typed in. No more", 256, 56, 209, 17)
$WhatToD5 = GUICtrlCreateLabel("digging through charmap.", 256, 72, 209, 17)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    GUISetOnEvent ($GUI_EVENT_CLOSE, "Exit1")
WEnd

Func SavetoIni()
    Iniwrite ( "C;\Var.ini", "[Characters]", "1", "" & GuiCtrlRead ($NewCtrl1) )
    Iniwrite ( "C;\Var.ini", "[Characters]", "2", "" & GuiCtrlRead ($NewCtrl2) )
    Iniwrite ( "C;\Var.ini", "[Characters]", "3", "" & GuiCtrlRead ($NewCtrl3) )
    Iniwrite ( "C;\Var.ini", "[Characters]", "4", "" & GuiCtrlRead ($NewCtrl4) )
    Iniwrite ( "C;\Var.ini", "[Characters]", "5", "" & GuiCtrlRead ($NewCtrl5) )
Endfunc

Func Send1()
    Send ("" & GuiCtrlRead ($NewCtrl1) ) 
EndFunc

Func Send2()
    Send ("" & GuiCtrlRead ($NewCtrl2) )
EndFunc

Func Send3()
    Send ("" & GuiCtrlRead ($NewCtrl3) )
EndFunc

Func Send4()
    Send ("" & GuiCtrlRead ($NewCtrl4) )
EndFunc

Func Send5()
    Send ("" & GuiCtrlRead ($NewCtrl5) )
EndFunc

func Exit1()
   Exit
endfunc

Everything works fine. Except reading/writing to the INI file. I've been trying for an hour, but no luck. Is it a simple syntax error? Am I just retarded? Please help.

note: I know this is a very simple script, but it DOES serve a purpose. My science teacher is always using special characters, like squared and stuff for math problems, and Instead of going to font and changing to subscript and back, I showed him Charmap, and now he goes there every chance possible to look for new, cool characters, and to get the Alt + numbers code of the characters. I'm making this so he can just set some characters, and hit Ctrl + number so it will type it in for him. (Mostly a practice script for me)


Share this post


Link to post
Share on other sites

off the top of head head right-quick, i don't think you need to include the brackets with the sections names...

$NewCtrl1 = GUICtrlCreateInput("" & IniRead ( "C;\var.ini", "Characters", "1", "10"), 63, 8, 161, 21)

Maybe try that and see how it goes.

Edited by evilertoaster

Share this post


Link to post
Share on other sites

This seems to work fine for me-

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Hotkeyset ( "^1",  "Send1" )
Hotkeyset ( "^2",  "Send2" )
Hotkeyset ( "^3",  "Send3" )
Hotkeyset ( "^4",  "Send4" )
Hotkeyset ( "^5",  "Send5" )

$MainGUI = GUICreate("Easy Char.", 470, 127, 287, 230)
$NewCtrl1 = GUICtrlCreateInput("" & IniRead ( "C:\var.ini", "Characters", "1", "10"), 63, 8, 161, 21)
$NewCtrl2 = GUICtrlCreateInput("" & IniRead ( "C:\var.ini", "Characters", "2", "10"), 63, 32, 161, 21)
$NewCtrl3 = GUICtrlCreateInput("" & IniRead ( "C:\var.ini", "Characters", "3", "10"), 63, 56, 161, 21)
$NewCtrl4 = GUICtrlCreateInput("" & IniRead ( "C:\var.ini", "Characters", "4", "10"), 63, 80, 161, 21)
$NewCtrl5 = GUICtrlCreateInput("" & IniRead ( "C:\var.ini", "Characters", "5", "10"), 63, 104, 161, 21)
$SaveButton = GUICtrlCreateButton("Save Current Characters", 224, 104, 121, 17, 0)
GUISetOnEvent ( $SaveButton, "SaveToIni" )
$Ctrl1Label = GUICtrlCreateLabel("Ctrl 1:", 4, 8, 28, 17)
$Ctrl2Label = GUICtrlCreateLabel("Ctrl 2:", 4, 32, 28, 17)
$Ctrl3Label = GUICtrlCreateLabel("Ctrl 3:", 4, 56, 28, 17)
$Ctrl4Label = GUICtrlCreateLabel("Ctrl 4:", 4, 80, 28, 17)
$Ctrl5Label = GUICtrlCreateLabel("Ctrl 5:", 4, 104, 28, 17)
$WhatToDo = GUICtrlCreateLabel("What to do:  Copy and a paste a character", 256, 8, 206, 17)
$WhatToD2 = GUICtrlCreateLabel("into the box and hit 'Save.' Then, hit CTRL", 256, 24, 204, 17)
$WhatToD3 = GUICtrlCreateLabel("+ the number specified, and the char-", 256, 40, 196, 17)
$WhatToD4 = GUICtrlCreateLabel("acter will be automatically typed in. No more", 256, 56, 209, 17)
$WhatToD5 = GUICtrlCreateLabel("digging through charmap.", 256, 72, 209, 17)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    GUISetOnEvent ($GUI_EVENT_CLOSE, "Exit1")
WEnd

Func SavetoIni()
    Iniwrite ( "C:\Var.ini", "Characters", "1", "" & GuiCtrlRead ($NewCtrl1) )
    Iniwrite ( "C:\Var.ini", "Characters", "2", "" & GuiCtrlRead ($NewCtrl2) )
    Iniwrite ( "C:\Var.ini", "Characters", "3", "" & GuiCtrlRead ($NewCtrl3) )
    Iniwrite ( "C:\Var.ini", "Characters", "4", "" & GuiCtrlRead ($NewCtrl4) )
    Iniwrite ( "C:\Var.ini", "Characters", "5", "" & GuiCtrlRead ($NewCtrl5) )
Endfunc

Func Send1()
    Send ("" & GuiCtrlRead ($NewCtrl1) ) 
EndFunc

Func Send2()
    Send ("" & GuiCtrlRead ($NewCtrl2) )
EndFunc

Func Send3()
    Send ("" & GuiCtrlRead ($NewCtrl3) )
EndFunc

Func Send4()
    Send ("" & GuiCtrlRead ($NewCtrl4) )
EndFunc

Func Send5()
    Send ("" & GuiCtrlRead ($NewCtrl5) )
EndFunc

func Exit1()
   Exit
endfunc

my var.ini-

[Characters]

1=10

2=11

3=12

4=13

5=14

Share this post


Link to post
Share on other sites

In the help file, it says it will make an Ini File if one doesn't exist.

It's not making one.

Other than that, it works, So thanks!

Edit: Actually, it wont write to the INI...

Edited by alex OF DEATH

Share this post


Link to post
Share on other sites

sorry forgot about that... this should work now,

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Hotkeyset ( "^1",  "Send1" )
Hotkeyset ( "^2",  "Send2" )
Hotkeyset ( "^3",  "Send3" )
Hotkeyset ( "^4",  "Send4" )
Hotkeyset ( "^5",  "Send5" )

$MainGUI = GUICreate("Easy Char.", 470, 127, 287, 230)
$NewCtrl1 = GUICtrlCreateInput(IniRead ( "C:\var.ini", "Characters", "1", "10"), 63, 8, 161, 21)
$NewCtrl2 = GUICtrlCreateInput(IniRead ( "C:\var.ini", "Characters", "2", "10"), 63, 32, 161, 21)
$NewCtrl3 = GUICtrlCreateInput(IniRead ( "C:\var.ini", "Characters", "3", "10"), 63, 56, 161, 21)
$NewCtrl4 = GUICtrlCreateInput(IniRead ( "C:\var.ini", "Characters", "4", "10"), 63, 80, 161, 21)
$NewCtrl5 = GUICtrlCreateInput(IniRead ( "C:\var.ini", "Characters", "5", "10"), 63, 104, 161, 21)
$SaveButton = GUICtrlCreateButton("Save Current Characters", 224, 104, 121, 17, 0)
GUICtrlSetOnEvent ( $SaveButton, "SaveToIni" )
$Ctrl1Label = GUICtrlCreateLabel("Ctrl 1:", 4, 8, 28, 17)
$Ctrl2Label = GUICtrlCreateLabel("Ctrl 2:", 4, 32, 28, 17)
$Ctrl3Label = GUICtrlCreateLabel("Ctrl 3:", 4, 56, 28, 17)
$Ctrl4Label = GUICtrlCreateLabel("Ctrl 4:", 4, 80, 28, 17)
$Ctrl5Label = GUICtrlCreateLabel("Ctrl 5:", 4, 104, 28, 17)
$WhatToDo = GUICtrlCreateLabel("What to do:  Copy and a paste a character", 256, 8, 206, 17)
$WhatToD2 = GUICtrlCreateLabel("into the box and hit 'Save.' Then, hit CTRL", 256, 24, 204, 17)
$WhatToD3 = GUICtrlCreateLabel("+ the number specified, and the char-", 256, 40, 196, 17)
$WhatToD4 = GUICtrlCreateLabel("acter will be automatically typed in. No more", 256, 56, 209, 17)
$WhatToD5 = GUICtrlCreateLabel("digging through charmap.", 256, 72, 209, 17)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    GUISetOnEvent ($GUI_EVENT_CLOSE, "Exit1")
WEnd

Func SavetoIni()
    Iniwrite ( "C:\Var.ini", "Characters", "1", GuiCtrlRead ($NewCtrl1) )
    Iniwrite ( "C:\Var.ini", "Characters", "2", GuiCtrlRead ($NewCtrl2) )
    Iniwrite ( "C:\Var.ini", "Characters", "3", GuiCtrlRead ($NewCtrl3) )
    Iniwrite ( "C:\Var.ini", "Characters", "4", GuiCtrlRead ($NewCtrl4) )
    Iniwrite ( "C:\Var.ini", "Characters", "5", GuiCtrlRead ($NewCtrl5) )
Endfunc

Func Send1()
    Send ("" & GuiCtrlRead ($NewCtrl1) ) 
EndFunc

Func Send2()
    Send ("" & GuiCtrlRead ($NewCtrl2) )
EndFunc

Func Send3()
    Send ("" & GuiCtrlRead ($NewCtrl3) )
EndFunc

Func Send4()
    Send ("" & GuiCtrlRead ($NewCtrl4) )
EndFunc

Func Send5()
    Send ("" & GuiCtrlRead ($NewCtrl5) )
EndFunc

func Exit1()
   Exit
endfunc

Share this post


Link to post
Share on other sites

besides the changes to the iniread/write lines the main difference is-

GUICtrlSetOnEvent ( $SaveButton, "SaveToIni" )
oÝ÷ ÚûºÚ"µÍÕRTÙ]Û][
    ÌÍÔØ]P]Û   ][ÝÔØ]UÒ[I][ÝÈ

I've done this alot becuase the first one come up on the scite inteli-sense first so i mistype it :shocked:

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...