Jump to content

When saving text from editbox


Recommended Posts

Link to comment
Share on other sites

Multi-line values are not valid in an INI file, so you have to replace the @CRLF with a token (typically "\n"):

$sText = StringReplace($sText, @CRLF, "\n")

And, of course, when you read it back:

$sText = StringReplace($sText, "\n", @CRLF)

: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

You want to be careful ending it out with "\n", if another program (written in say, python) reads that it's going to throw things off as '\n' is interpreted as a catch-all linebreak.

I will generally use an unusual sequence of characters (eg: #8#, or something of that nature) that is unlikely to come up anywhere. Whatever you use, it might make life easier if you include a key=value pair noting this somewhere

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

You want to be careful ending it out with "\n", if another program (written in say, python) reads that it's going to throw things off as '\n' is interpreted as a catch-all linebreak.

I will generally use an unusual sequence of characters (eg: #8#, or something of that nature) that is unlikely to come up anywhere. Whatever you use, it might make life easier if you include a key=value pair noting this somewhere

Unfortunately, there is no exact standard for INI file formatting, just some general guidelines and "as used" practices. If you were implementing your own, you could even make it accept multi-line values.

In this case linebreaks are exactly what's being tokenized, so "\n" is appropriate, but it could be anything you deem unique enough for your situation.

: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

Multi-line values are not valid in an INI file, so you have to replace the @CRLF with a token (typically "\n"):

$sText = StringReplace($sText, @CRLF, "\n")

And, of course, when you read it back:

$sText = StringReplace($sText, "\n", @CRLF)

:mellow:

Hello PsaltyDS and Fulano, im not understanding wht you are saing.

On my code im not using that line to save my info, im going to put here my Code when i Press the Save button.

Hoppe you can understand it, and help me to use your line on my code.

SAVE PART CODE:

Func _Check4Gravar()
        $answer = MsgBox(36, "Wanning", "Tem a certeza que quer gravar?", 8 )
        If $answer = 6 Then
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Nome" , GUICtrlRead($InputNome))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Contacto" , GUICtrlRead($InputContacto))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Email" , GUICtrlRead($InputEmail))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Observações" , GUICtrlRead($EditBox_Obs))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Ultimo Contacto" , GUICtrlRead($InputUltimoContacto))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Proximo Contacto" , GUICtrlRead($InputProximoContacto))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Depositos" , GUICtrlRead($EditBox_Depositos))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Titulos" , GUICtrlRead($EditBox_Titulos))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "FI" , GUICtrlRead($EditBox_FI))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "BSV" , GUICtrlRead($EditBox_BSV))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "SNV" , GUICtrlRead($EditBox_SNV))
    IniWrite ( "Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "SV" , GUICtrlRead($EditBox_SV))
    EndIf   
EndFunc

RELOAD ALL INFO:

Func _Check4Procurar()
GUICtrlSetData ($InputNome, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Nome", "Informação não encontrada"))
GUICtrlSetData ($InputContacto, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Contacto", "Informação não encontrada"))
GUICtrlSetData ($InputEmail, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Email", "Informação não encontrada"))
GUICtrlSetData ($EditBox_Obs, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Observações", "Informação não encontrada"))
GUICtrlSetData ($InputUltimoContacto, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Ultimo Contacto", "Informação não encontrada"))
GUICtrlSetData ($InputProximoContacto, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Proximo Contacto", "Informação não encontrada"))
GUICtrlSetData ($EditBox_Depositos, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Depositos", "Informação não encontrada"))
GUICtrlSetData ($EditBox_Titulos, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "Titulos", "Informação não encontrada"))
GUICtrlSetData ($EditBox_FI, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "FI", "Informação não encontrada"))
GUICtrlSetData ($EditBox_BSV, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "BSV", "Informação não encontrada"))
GUICtrlSetData ($EditBox_SNV, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "SNV", "Informação não encontrada"))
GUICtrlSetData ($EditBox_SV, IniRead ("Base de Contactos BES.ini", GUICtrlRead($InputN_Adesao) , "SV", "Informação não encontrada"))
EndFunc

Hoppe you can now, inlite me on how to use you code for multi-line on editbox.

Thx for all the help

Link to comment
Share on other sites

Need a simpler demo to talk about. This demo tries to use multi-line values from the edit boxes straight to\from the INI file:

#include <GuiConstantsEx.au3>

$sINI = @ScriptDir & "\Test1.ini"
$hGUI = GUICreate("INI Test", 350, 350)
$idEdit1 = GUICtrlCreateEdit("", 10, 10, 330, 130)
$idEdit2 = GUICtrlCreateEdit("", 10, 150, 330, 130)
$idButton1 = GUICtrlCreateButton("READ INI", 50, 300, 100, 30)
$idButton2 = GUICtrlCreateButton("WRITE INI", 200, 300, 100, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idButton1
            ; Read INI
            $sText = IniRead($sINI, "Test", "Edit1", "")
            GUICtrlSetData($idEdit1, $sText)
            $sText = IniRead($sINI, "Test", "Edit2", "")
            GUICtrlSetData($idEdit2, $sText)

        Case $idButton2
            ; Write INI
            $sText = GUICtrlRead($idEdit1)
            IniWrite($sINI, "Test", "Edit1", $sText)
            $sText = GUICtrlRead($idEdit2)
            IniWrite($sINI, "Test", "Edit2", $sText)
    EndSwitch
WEnd

Now look at how much better it's handled this way (remember you can change the token "\n" to whatever works for you):

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idButton1
            ; Read INI
            $sText = StringReplace(IniRead($sINI, "Test", "Edit1", ""), "\n", @CRLF)
            GUICtrlSetData($idEdit1, $sText)
            $sText = StringReplace(IniRead($sINI, "Test", "Edit2", ""), "\n", @CRLF)
            GUICtrlSetData($idEdit2, $sText)

        Case $idButton2
            ; Write INI
            $sText = StringReplace(GUICtrlRead($idEdit1), @CRLF, "\n")
            IniWrite($sINI, "Test", "Edit1", $sText)
            $sText = StringReplace(GUICtrlRead($idEdit2), @CRLF, "\n")
            IniWrite($sINI, "Test", "Edit2", $sText)
    EndSwitch
WEnd

: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

Need a simpler demo to talk about. This demo tries to use multi-line values from the edit boxes straight to\from the INI file:

#include <GuiConstantsEx.au3>

$sINI = @ScriptDir & "\Test1.ini"
$hGUI = GUICreate("INI Test", 350, 350)
$idEdit1 = GUICtrlCreateEdit("", 10, 10, 330, 130)
$idEdit2 = GUICtrlCreateEdit("", 10, 150, 330, 130)
$idButton1 = GUICtrlCreateButton("READ INI", 50, 300, 100, 30)
$idButton2 = GUICtrlCreateButton("WRITE INI", 200, 300, 100, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idButton1
            ; Read INI
            $sText = IniRead($sINI, "Test", "Edit1", "")
            GUICtrlSetData($idEdit1, $sText)
            $sText = IniRead($sINI, "Test", "Edit2", "")
            GUICtrlSetData($idEdit2, $sText)

        Case $idButton2
            ; Write INI
            $sText = GUICtrlRead($idEdit1)
            IniWrite($sINI, "Test", "Edit1", $sText)
            $sText = GUICtrlRead($idEdit2)
            IniWrite($sINI, "Test", "Edit2", $sText)
    EndSwitch
WEnd

Now look at how much better it's handled this way (remember you can change the token "\n" to whatever works for you):

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idButton1
            ; Read INI
            $sText = StringReplace(IniRead($sINI, "Test", "Edit1", ""), "\n", @CRLF)
            GUICtrlSetData($idEdit1, $sText)
            $sText = StringReplace(IniRead($sINI, "Test", "Edit2", ""), "\n", @CRLF)
            GUICtrlSetData($idEdit2, $sText)

        Case $idButton2
            ; Write INI
            $sText = StringReplace(GUICtrlRead($idEdit1), @CRLF, "\n")
            IniWrite($sINI, "Test", "Edit1", $sText)
            $sText = StringReplace(GUICtrlRead($idEdit2), @CRLF, "\n")
            IniWrite($sINI, "Test", "Edit2", $sText)
    EndSwitch
WEnd

:mellow:

Thx maite, your exemples are the best...

Im going to try and implemante them on my code, the 2nd exemple its working better them the 1st one, because, the 1st one doesnt write the "line 2" if if exists, but if i use the 2nd exemple, and save the multi lines, the 1st ex. can read the multi-lines and separete them with a "\".

Im gogint to a birthdate dinner now, but tomorrow, ill post here the resolt of your code.

Thx alote for your code/replays.

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