Jump to content

Saving an edit line as a variable


Recommended Posts

Hey im currently trying to save an edit line as a variable but I can't get it to work

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Test", 730, 670, 557, 189)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 705, 513)
GUICtrlSetData(-1, "This is a test line")
$Button1 = GUICtrlCreateButton("Test", 264, 568, 81, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

global $line1 = _GUICtrlEdit_GetLine($Edit1, 0))

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
                
                Case $Button1
                
                MsgBox($MB_SYSTEMMODAL, "Information", $line1)

        EndSwitch
    WEnd
EndFunc   

Hope someone can help me with this or point me in a direction.

Edited by xtreempje
Link to comment
Share on other sites

When I use GUICtrlRead I don't get anything popped up in my msgbox.

but when I do

MsgBox($MB_SYSTEMMODAL, "Information", _GUICtrlEdit_GetLine($Edit1, 0)))

It does work and gives me the line in the msgbox but I want it to be saved as a variable so I can just use

MsgBox($MB_SYSTEMMODAL, "Information", $line1)

 

Link to comment
Share on other sites

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiEdit.au3>

#Region ### START Koda GUI section ### Form=
Global $Form2 = GUICreate("Test", 730, 670, 557, 189)
Global $Edit1 = GUICtrlCreateEdit("", 8, 8, 705, 513)
Global $Button1 = GUICtrlCreateButton("ok", 10, 600, 30, 25)
Global $MyData = "This is a test line1" & @CRLF & "This is a test line2"
GUICtrlSetData($Edit1, $MyData)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $Button1
            MsgBox($MB_SYSTEMMODAL, "Information", $MyData)

    EndSwitch
WEnd


global $line1 = _GUICtrlEdit_GetLine($Edit1, 0)
MsgBox($MB_SYSTEMMODAL, "Information", $line1)

 

I know that I know nothing

Link to comment
Share on other sites

put on top of your script

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4  ;-w 5 -w 6 -w 7

at least until comment he will point out mistakes

like this

MsgBox($MB_SYSTEMMODAL, "Information", _GUICtrlEdit_GetLine($Edit1, 0)))

or this

global $line1 = _GUICtrlEdit_GetLine($Edit1, 0))

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Hey I have another question.

I made it so it saves the text in a ini file and loads the text from the ini file but it only loads 1 line of text from the ini file even if i write down 500 lines and press save.

the ini file does contain all my text but it only loads 1 line.

 

This is how I load from the ini file :

GUICtrlSetData($Edit1, IniRead("Config.ini", "Config", "Edit", "Example"))

This is how i save to the ini file :

IniWrite(@ScriptDir & "/Config.ini","Config","Edit",GUICtrlRead($Edit1))

and this is the ini file :

[Config]
Edit=This is a test
a test to check if it
loads more lines 
than 1 
but it 
does not

 

This is the full script for now to try get it to work

Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 730, 670, 557, 189)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 705, 513)
GUICtrlSetData(30, "Example")
$Save = GUICtrlCreateButton("Save", 24, 616, 193, 33)
$Close = GUICtrlCreateButton("Close", 235, 616, 137, 33)

GUICtrlSetData($Edit1, IniRead("Config.ini", "Config", "Edit", "Example"))

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_main()

        

Func _main()
    GUISetState(@SW_SHOWNORMAL)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        
Case $Save
                IniWrite(@ScriptDir & "/Config.ini","Config","Edit",GUICtrlRead($Edit1))
Save()
                
            
        EndSwitch
    WEnd
EndFunc

 

Link to comment
Share on other sites

What you can do is either to save the lines from the edit box in each key value 

e.g.

Quote

1=Line 1

2=Line 2

or to replace the return chars (@crlf) from the edit box with some custom word, which will usually not be used in the text, like @R@ in this example:

#include <GUIConstants.au3>
$Form2 = GUICreate("Form2", 730, 670, 557, 189)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 705, 513)
GUICtrlSetData(30, "Example")
$Save = GUICtrlCreateButton("Save", 24, 616, 193, 33)
$Load = GUICtrlCreateButton("Load", 335, 616, 137, 33)

GUICtrlSetData($Edit1, StringReplace(IniRead(@ScriptDir & "\Config.ini", "Config", "Edit", "Example"), "@R@", @CRLF))

GUISetState(@SW_SHOW)

_main()

Func _main()
    GUISetState(@SW_SHOWNORMAL)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Load
                GUICtrlSetData($Edit1, StringReplace(IniRead(@ScriptDir &"\Config.ini", "Config", "Edit", "Example"), "@R@", @CRLF))
            Case $Save
                IniWrite(@ScriptDir & "\Config.ini", "Config", "Edit", StringReplace(GUICtrlRead($Edit1), @CRLF, "@R@"))
        EndSwitch
    WEnd
EndFunc   ;==>_main

 

Edited by Dan_555

Some of my script sourcecode

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