Sign in to follow this  
Followers 0
NELyon

Text in an edit box=variable

17 posts in this topic

Heres what i am trying to say with that strange title. I need help with something. Is there any way to assign the text entered into an edit box to a variable?

EXAMPLE:

#include <GUIconstants.au3>
GUIcreate("Whatev")
GUICtrlCreateEdit("Type Text Here")

Yeah i know that code is missing some args for GUICtrlCreateEdit but you get the idea.

Is there any way to make "type your text here" or what the person typed in as $variable1?

This is all for a small project i am working on...... when i finish it i will post it in scripts & scraps

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>

GUICreate("My GUI edit") ; will create a dialog box that when displayed is centered

$myedit=GUICtrlCreateEdit ("First line"& @CRLF, 176,32,121,97,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()

; will be append dont' forget 3rd parameter
GUICtrlSetData ($myedit, "Second line",1)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
$s_data = GUICtrlRead($myedit)  ; just to show you how to get the data
MsgBox(0,"Data from Edit Box",$s_data)


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

AGH YES! thank you.

Hmm... that first part is strait out of the beta help file... don't knw where the next parts are from :D

EDIT: ok, so i got this. BUT, this won't work

#include <GUIConstants.au3>
HotKeySet("{enter}", "savefile")

GUICreate("My GUI edit"); will create a dialog box that when displayed is centered

$myedit=GUICtrlCreateEdit ("First line"& @CRLF, 176,32,121,97,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()

; will be append dont' forget 3rd parameter
GUICtrlSetData ($myedit, "Second line",1)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend


Func Savefile()
$file = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, $myedit)


FileClose($file)
EndFunc

supposed to write the text from $myedit to test.txt. The filewrite function worked fine by itself (not with the variables, just plain text.) but this won't write :D

Edited by codemyster

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

GUICreate("My GUI edit"); will create a dialog box that when displayed is centered

$myedit = GUICtrlCreateEdit("First line" & @CRLF, 176, 32, 121, 97, $ES_AUTOVSCROLL + $WS_VSCROLL)
$button = GUICtrlCreateButton("Save", 10, 300, 120, 25)
GUISetState()

; will be append dont' forget 3rd parameter
GUICtrlSetData($myedit, "Second line", 1)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            _Savefile(GUICtrlRead($myedit))
    EndSelect
WEnd


Func _Savefile($s_text)
    $file = FileOpen("test.txt", 1)
    
; Check if file opened for writing OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
    FileWrite($file, $s_text)
    
    
    FileClose($file)
EndFunc  ;==>Savefile


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank you very much. By the way, what i am trying to make is a code snippet holder... something i will need to use ALOT. it holds the data in snippets.txt

EDIT: heres my first prototype/ leaves much to be desired. one thing i am trying to find out how to do is show the data of the text file in the GUI. You must first create a snippets.txt file in the scripts directory

#include <GUIConstants.au3>

GUICreate("My GUI edit", 350, 350)

$myedit = GUICtrlCreateEdit("Welcome! Type your codes here!" & @CRLF, 30, 50, 300, 121, $ES_AUTOVSCROLL + $WS_VSCROLL)
$button = GUICtrlCreateButton("Save", 175, 250, 120, 25)
$button_2 = GUICtrlCreateButton ("Clear", 50, 250, 120, 25)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            _Savefile(GUICtrlRead($myedit))
        Case $msg = $button_2
            GUICtrlSetData($myedit, "")
    EndSelect
WEnd


Func _Savefile($s_text)
    $file = FileOpen("Snippets.txt", 1)
    
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to save file. Really sorry!")
        Exit
    EndIf

    FileWrite($file, $s_text)
    
    
    FileClose($file)
EndFunc

Where are those autoit codes when you need 'em?

EDIT2: what the? it stoped working on me?!?! i added the clear button in Scite... could that have mesed it up?

Edited by codemyster

Share this post


Link to post
Share on other sites

bump

can anyone help?

Share this post


Link to post
Share on other sites

Hmm... that brings up my computers properties... what's it supposed to do?

Share this post


Link to post
Share on other sites

Hmm... that brings up my computers properties... what's it supposed to do?

shouldn't from with-in SciTE, also might try Tools/Snippet Holder from within SciTE


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

when in the new version of Scite Press CTRL+ALT+S and it will bring up a Code Snippet Window for you :D

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Ok, i got everything working fine, almost. I started over and got this:

#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>

GuiCreate("Snippets Holder", 346, 373,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Edit_1 = GuiCtrlCreateEdit("Snippets", 30, 10, 280, 230)
$Button_2 = GuiCtrlCreateButton("Clear", 20, 260, 130, 30)
$Button_3 = GuiCtrlCreateButton("Save", 180, 260, 140, 30)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_2
        GUICtrlSetData($Edit_1, "")
    Case $msg = $Button_3
        FileWrite("snippets.txt", $Edit_1)
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

This works except the filewrite part... all it writes is a "3" in the text file every time i click the save button.

EDIT: i also tried INIWriting it but it still just wrote a "3"

Edited by codemyster

Share this post


Link to post
Share on other sites

Ok, i got everything working fine, almost. I started over and got this:

#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>

GuiCreate("Snippets Holder", 346, 373,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Edit_1 = GuiCtrlCreateEdit("Snippets", 30, 10, 280, 230)
$Button_2 = GuiCtrlCreateButton("Clear", 20, 260, 130, 30)
$Button_3 = GuiCtrlCreateButton("Save", 180, 260, 140, 30)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_2
        GUICtrlSetData($Edit_1, "")
    Case $msg = $Button_3
        FileWrite("snippets.txt", $Edit_1)
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

This works except the filewrite part... all it writes is a "3" in the text file every time i click the save button.

EDIT: i also tried INIWriting it but it still just wrote a "3"

It writes a 3 because that's the EditBox's Control ID, you didn't tell it to write anything else. Now if you replaced $Edit_1 with GUICtrlRead($Edit_1) now your telling it to write what is in the Edit box.

[center]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.[/center]

Share this post


Link to post
Share on other sites

Yes! Thanks smOke_n

Share this post


Link to post
Share on other sites

Yes! Thanks smOke_n

No problem, cameronsdad is always happy to help :D

[center]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.[/center]

Share this post


Link to post
Share on other sites

rofl

Off topic:

I know a kid who always types that "roffles"

Share this post


Link to post
Share on other sites

I decided to make something else instead of a snippet holder. Check out the link in my sig (SimpleEditor)

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  
Followers 0