Jump to content

[Solved] Question about INI files


mini
 Share

Recommended Posts

Hello, how can i generate several INI files with different names when saving my info.

I have a input box for clients, right now it only saves all my clients in ONE ini file.

It saves like this...

IniWrite ( "Base de Contactos BES.ini" , GUICtrlRead($InputIDCB) , "Nome" , GUICtrlRead($InputNome))

the ini file have this name:Base de Contactos BES.ini

In the ini file it goes like this:

[Client1]

Name=123

Now im trying to change the name of the INI file to the name of the client, sow it cood save more then one file.

I want to change the way i save my files.

EX:

IniWrite ( get the name on the $InputIDCB , GUICtrlRead($InputIDCB) , "Nome" , GUICtrlRead($InputNome))

Is it ever possible? Edited by mini
Link to comment
Share on other sites

In the example you posted, how did you get the client name you used for the section name?

Why can't you use the same for the file name? All you need is to append ".ini" to it.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

In the example you posted, how did you get the client name you used for the section name?

Why can't you use the same for the file name? All you need is to append ".ini" to it.

:mellow:

This is my test prgram...

I have 2 inputbox, one that is use to search for the client, and one you put the name of client, for saving the info.

Sow i use this line to get the "$inputname" of the client and use the same to generate the file name by reading the "$inputIDCB"

IniWrite ( GUICtrlRead($InputIDCB) , GUICtrlRead($InputIDCB) , "Name" , GUICtrlRead($InputName))

Ahhh---and like this "IniWrite ( GUICtrlRead($InputIDCB)...bla bla..." i cant creat a ".ini" file...

What do you mean for "append". sorry about my English, im not very good on it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test",  537, 451)
$sINI = @ScriptDir
;Buttons
$Procurar = GUICtrlCreateButton("Procurar", 24, 48, 75, 25)
$Gravar = GUICtrlCreateButton("Gravar", 24, 400, 75, 25)
$Limpar = GUICtrlCreateButton("Limpar", 112, 400, 75, 25)
$Apagar = GUICtrlCreateButton("Apagar", 120, 48, 75, 25)
;Input
$InputIDCB = GUICtrlCreateInput("IDCB", 24, 88, 169, 21)
;Input
$InputNome = GUICtrlCreateInput("", 24, 144, 169, 21)


$iEditWidth = 289
$iEditHeight = 377

; create edit without scroll bars
$EditBox_Obs = GUICtrlCreateEdit("", 216, 48, $iEditWidth, $iEditHeight, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL))

$hLabel = GUICtrlCreateLabel("", 420, 10, 70, 20)

GUISetState()

; Set scrolbar flags
$fHSCROLL = False
$fVSCROLL = False

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
                    Case $Procurar
            _Check4Procurar()
            $sText = StringReplace(IniRead($sINI, GUICtrlRead($InputIDCB) , "Observações", "N / A"), "\n", @CRLF)
            GUICtrlSetData($EditBox_Obs, $sText)
                    Case $Gravar
            _Check4Gravar() 
                        $sText = StringReplace(GUICtrlRead($EditBox_Obs), @CRLF, "\n")
            IniWrite($sINI, GUICtrlRead($InputIDCB) , "Observações", $sText)
                    Case $Limpar
            _Check4Limpar()
    EndSwitch

    ; Do we need scrollbars?
    _Check_Scrolls($EditBox_Obs)

WEnd
Func _Check4Gravar()
$answer = MsgBox(36, "Aviso", "Tem a certeza que quer gravar?",8)
If $answer = 6 Then
    IniWrite ( GUICtrlRead($InputIDCB) , GUICtrlRead($InputIDCB) , "Nome" , GUICtrlRead($InputNome))
    
    EndIf   
EndFunc


Func _Check4Procurar()
    GUICtrlSetData ($InputNome, IniRead (GUICtrlRead($InputIDCB), GUICtrlRead($InputIDCB) , "Nome", "N / A"))
EndFunc

Func _Check4Limpar()
$answer = MsgBox(36, "Aviso", "Tem a certeza que quer Limpar?", 8 )
If $answer = 6 Then
 GuiCtrlSetData ($InputIDCB, "")
 GuiCtrlSetData ($InputNome, "")
 EndIf
EndFunc
Func _Check_Scrolls($hControl)

    ; Get position of GUI
    $aPos = WinGetPos($hGUI)
    ; Create a label outside the GUI with no size parameters
    $hTester = GUICtrlCreateLabel(GUICtrlRead($hControl), $aPos[0] + $aPos[2] + 10, $aPos[1])
    ; Get the size of the label - which is the size of the text
    $aSize = ControlGetPos($hGUI, "", $hTester)
    ; Delete the label
    GUICtrlDelete($hTester)

    ; Show current size of text block less margins
    ;GUICtrlSetData($hLabel, $aSize[2] - 8 & " x " & $aSize[3] - 10)

    ; Check text width and adjust horizontal scroll bar style as necessary
    If $aSize[2] > $iEditWidth - 8 Then
        If $fHSCROLL = False Then
            $iStyle   = _WinAPI_GetWindowLong(GUICtrlGetHandle($hControl), $GWL_STYLE)
            GUICtrlSetStyle($EditBox_Obs, BitOR($iStyle, $WS_HSCROLL))
            $fHSCROLL = True
        EndIf
    Else
        If $fHSCROLL = True Then
            $iStyle   = _WinAPI_GetWindowLong(GUICtrlGetHandle($hControl), $GWL_STYLE)
            GUICtrlSetStyle($EditBox_Obs, BitAND($iStyle, BitNOT($WS_HSCROLL)))
            $fHSCROLL = False
            ; Force whole line to show
            ControlSend($hGUI, "", $EditBox_Obs, "{HOME}{END}")
        EndIf
    EndIf

    ; Check text height and adjust vertical scroll bar style as necessary
    If $aSize[3] > $iEditHeight - 6 Then
        If $fVSCROLL = False Then
            $iStyle   = _WinAPI_GetWindowLong(GUICtrlGetHandle($hControl), $GWL_STYLE)
            GUICtrlSetStyle($EditBox_Obs, BitOR($iStyle, $WS_VSCROLL))
            $fVSCROLL = True
        EndIf
    Else
        If $fVSCROLL = True Then
            $iStyle   = _WinAPI_GetWindowLong(GUICtrlGetHandle($hControl), $GWL_STYLE)
            GUICtrlSetStyle($hEdit, BitAND($iStyle, BitNOT($WS_VSCROLL)))
            $fVSCROLL = False
        EndIf
    EndIf

EndFunc
Link to comment
Share on other sites

The append operator in AutoIt (and many other languages) is "&", so you could use:

IniWrite ( GUICtrlRead($InputIDCB) & ".ini", GUICtrlRead($InputIDCB), "Name" ,GUICtrlRead($InputName))

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The append operator in AutoIt (and many other languages) is "&", so you could use:

IniWrite ( GUICtrlRead($InputIDCB) & ".ini", GUICtrlRead($InputIDCB), "Name" ,GUICtrlRead($InputName))

:D

:mellow::(:lol::P:evil::P

Thank you very much, i changed the:

$sINI = @ScriptDir
to
$sINI = @ScriptDir & "\"

plus this part:

$sText = StringReplace(IniRead($sINI, GUICtrlRead($InputIDCB) , "Observações", "N / A"), "\n", @CRLF)
            GUICtrlSetData($EditBox_Obs, $sText)
to
$sText = StringReplace(IniRead($sINI & GUICtrlRead($InputIDCB) & ".ini", GUICtrlRead($InputIDCB) , "Observações", "N / A"), "\n", @CRLF)
            GUICtrlSetData($EditBox_Obs, $sText)
And

$sText = StringReplace(GUICtrlRead($EditBox_Obs), @CRLF, "\n")
            IniWrite($sINI, GUICtrlRead($InputIDCB) , "Observações", $sText)
to

$sText = StringReplace(GUICtrlRead($EditBox_Obs), @CRLF, "\n")
            IniWrite($sINI & GUICtrlRead($InputIDCB) & ".ini", GUICtrlRead($InputIDCB) , "Observações", $sText)
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...