Sign in to follow this  
Followers 0
r2dak

how to let a user write a message and then save it to a file

7 posts in this topic

#1 ·  Posted (edited)

hi :bye: I'm new to autoit and can you tell me how to let a user write a message and then save it to a file

this is what i've coded so far and its working fine but its not suitable for a longer message with multiple lines

can you tell me how can i do that

thank you :idiot:

#include <File.au3>
$var = "msg.txt"
$num = InputBox("email address", "please enter your email address", "r2dak@exmaple.com", "",270,130)
$txt= InputBox("write your text ", "Write your Message", "your text here", "",270,130)
_FileWriteToLine($var, 1, "name: " & $num , 1)
;_FileWriteToLine($var, 13, "Date:" & $dnt , 1)
_FileWriteToLine($var, 2, "msg :" & $txt , 1)
MsgBox(64, "Thank you","thanks we will respond soon")
Edited by r2dak

[center][font=comic sans ms,cursive]PEACE & LOVE[/font][/center]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi @r2dak, and welcome to AutoitScript forum :)

Because you're new here you should read the forum rules.

And here's an example for what you want:

$GUI = GUICreate("Form1", 307, 439, 192, 114)
$Label1 = GUICtrlCreateLabel("Message:", 8, 8, 50, 17)
$TextEdit = GUICtrlCreateEdit("", 8, 32, 289, 369)
$SaveButton = GUICtrlCreateButton("Save", 112, 408, 75, 25)
GUISetState(@SW_SHOW)
$file=FileOpen("msg.txt",2)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3 ;$GUI_EVENT_CLOSE
Exit
Case $SaveButton
$data=GUICtrlRead($TextEdit)
FileWrite($file,$data)
FileClose($file)
MsgBox(64, "Thank you","thanks we will respond soon")
Exit
EndSwitch
Sleep(10)
WEnd

If you have any ohter questions, we are waiting! :D

Edited by mihaibr

Share this post


Link to post
Share on other sites

thank you very much mihaibr its working :thumbsup:

only one little request but only if you have time, can you explain this code a little please, i just started learning autoit few days ago and just trying to understand the it properly :lol:

thank you


[center][font=comic sans ms,cursive]PEACE & LOVE[/font][/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

ok

Posted Image

$GUI = GUICreate("Form1", 307, 439)

Will create a window with the title Form1 that has 307pixels width and 439pixels height

$Label1 = GUICtrlCreateLabel("Message:", 8, 8, 50, 17)

Will create a static Label control ,with the text "Message:",with left coordonate 8 and the right coordonate 8,width 50 pixels and height 17

$TextEdit = GUICtrlCreateEdit("", 8, 32, 289, 369)

Will create an Edit control,with left 8px,top 32px,width 289px and height 369px

$SaveButton = GUICtrlCreateButton("Save", 112, 408, 75, 25)

Will create a button with the text "Save", left 112px,top 408px,width 75px and height 25px

GUISetState(@SW_SHOW)

Will set the GUI state as "Show"

$file=FileOpen("msg.txt",2)

FileOpen opens a text file for reading or writing.

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case -3 ;$GUI_EVENT_CLOSE

Exit

Case $SaveButton

$data=GUICtrlRead($TextEdit)

FileWrite($file,$data)

FileClose($file)

MsgBox(64, "Thank you","thanks we will respond soon")

Exit

EndSwitch

Sleep(10)

WEnd

This is the main loop of the program

$nMsg = GUIGetMsg()

Polls the GUI to see if any events have occurred.

Case -3 ;$GUI_EVENT_CLOSE

Exit

Check if the "x" (close) button is pressend and close the program

Case $SaveButton

$data=GUICtrlRead($TextEdit)

FileWrite($file,$data)

FileClose($file)

MsgBox(64, "Thank you","thanks we will respond soon")

Exit

Check if the "Save" button is pressed and then save the read the text from the Edit control($TextEdit) and save it into $data

Then using FileWrite he write the $data into the file

Then shows the MessageBox and exit

Hope you understant something

Sorry for my bad english.

Here you can find all functions: http://www.autoitscript.com/autoit3/docs/functions.htm

Here is the documentation: http://www.autoitscript.com/autoit3/docs/

Edited by mihaibr
1 person likes this

Share this post


Link to post
Share on other sites

Thank you very much now i got it

don't worry about the English bro

even my English is really bad muttley its not my first language

i'm really thankful to for this

you ROCK :guitar:


[center][font=comic sans ms,cursive]PEACE & LOVE[/font][/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Erm, I forgot, if you want to create GUIs/Forms easyer you can use Koda (press ALT+M in SciTE or Tools->Koda(Form Designer) )

If you got any other questions I wait them.(You can also PM me ;) )

Edited by mihaibr

Share this post


Link to post
Share on other sites

wow that ALT+M wonderful :ILA:

thanks you very much i'll PM you if i need any Help


[center][font=comic sans ms,cursive]PEACE & LOVE[/font][/center]

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