Jump to content

Input Box question


Recommended Posts

How do you write a text entered into an input box onto a text file.

For example,

#include <GuiConstants.au3>
#include <Inet.au3>
#include <GUIConstantsEx.au3>

; GUI Creation
GUICreate("Data", 500, 420)
GUICtrlCreateTabItem("Data")
$labelnaam = GUICtrlCreateLabel("Name : ", 60, 40)
$Button_word = GUICtrlCreateButton("Write", 400, 350)
$input_naam = GUICtrlCreateInput("", 100, 40, 130, 20)
; GUI Show
GUISetState(@SW_SHOW)
$file = FileOpen("ak.txt",0)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Button_word
            $read_input = GUICtrlRead($input_naam)
            FileWrite($file, "12"&$Read_Input&"34")
            FileClose($file)
    EndSelect
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

It works when I make it display the input on Message box but it doesn't write it to a file, What is the problem?!

There are 10 kinds of people, those who understand me and those who don't.
Link to comment
Share on other sites

change it to this.. u r missing an exitloop. so ur while loop never ends.. it keeps on executing.

#include <GuiConstants.au3>
#include <Inet.au3>
#include <GUIConstantsEx.au3>

; GUI Creation
GUICreate("Data", 500, 420)
GUICtrlCreateTabItem("Data")
$labelnaam = GUICtrlCreateLabel("Name : ", 60, 40)
$Button_word = GUICtrlCreateButton("Write", 400, 350)
$input_naam = GUICtrlCreateInput("", 100, 40, 130, 20)
; GUI Show
GUISetState(@SW_SHOW)
$file = FileOpen("c:\ak.txt",2)

While 1
    $msg = GUIGetMsg()
   if  $msg = $Button_word Then
            $read_input = GUICtrlRead($input_naam)
            FileWrite($file, "12"&$Read_Input&"34")
            FileClose($file)
            ExitLoop
    Endif
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

change it to this.. u r missing an exitloop. so ur while loop never ends.. it keeps on executing.

#include <GuiConstants.au3>
#include <Inet.au3>
#include <GUIConstantsEx.au3>

; GUI Creation
GUICreate("Data", 500, 420)
GUICtrlCreateTabItem("Data")
$labelnaam = GUICtrlCreateLabel("Name : ", 60, 40)
$Button_word = GUICtrlCreateButton("Write", 400, 350)
$input_naam = GUICtrlCreateInput("", 100, 40, 130, 20)
; GUI Show
GUISetState(@SW_SHOW)
$file = FileOpen("c:\ak.txt",2)

While 1
    $msg = GUIGetMsg()
   if  $msg = $Button_word Then
            $read_input = GUICtrlRead($input_naam)
            FileWrite($file, "12"&$Read_Input&"34")
            FileClose($file)
            ExitLoop
    Endif
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
I have changed it and still no progress..

I have managed to make it write but it only writes the default value of the input box,

There are 10 kinds of people, those who understand me and those who don't.
Link to comment
Share on other sites

  • Moderators

akfourtyseven,

1. Perhaps if you opened your file in Write mode?

Mode (read or write) to open the file in.

Can be a combination of the following:

0 = Read mode

1 = Write mode (append to end of file)

2 = Write mode (erase previous contents)

2. You are also closing your file after the first write. Put FileClose as part of your exit code.

3. You are not writing what you read - use the same spelling for the GUICtrlRead and FileWrite.

Try this:

#include <GuiConstants.au3>
#include <Inet.au3>
#include <GUIConstantsEx.au3>

; GUI Creation
GUICreate("Data", 500, 420)
GUICtrlCreateTabItem("Data")
$labelnaam = GUICtrlCreateLabel("Name : ", 60, 40)
$Button_word = GUICtrlCreateButton("Write", 400, 350)
$input_naam = GUICtrlCreateInput("", 100, 40, 130, 20)
; GUI Show
GUISetState(@SW_SHOW)
$file = FileOpen("ak.txt",1)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Button_word
            $read_input = GUICtrlRead($input_naam)
            FileWrite($file, "12" & $read_input & "34")
        Case $msg = $GUI_EVENT_CLOSE
            FileClose($file)
            ExitLoop
    EndSelect
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hey

I just tested with the above code. It works perfectly well. It creates a file in C drive, named ak.txt. and writes 12*****34. **** represents i/p.

What exactly is the problem.

Is it creating the file or not. n if it is then what is it writing to the file.

Also plz tell me the version u r using

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

akfourtyseven,

1. Perhaps if you opened your file in Write mode?

Mode (read or write) to open the file in.

Can be a combination of the following:

0 = Read mode

1 = Write mode (append to end of file)

2 = Write mode (erase previous contents)

2. You are also closing your file after the first write. Put FileClose as part of your exit code.

3. You are not writing what you read - use the same spelling for the GUICtrlRead and FileWrite.

Try this:

#include <GuiConstants.au3>
#include <Inet.au3>
#include <GUIConstantsEx.au3>

; GUI Creation
GUICreate("Data", 500, 420)
GUICtrlCreateTabItem("Data")
$labelnaam = GUICtrlCreateLabel("Name : ", 60, 40)
$Button_word = GUICtrlCreateButton("Write", 400, 350)
$input_naam = GUICtrlCreateInput("", 100, 40, 130, 20)
; GUI Show
GUISetState(@SW_SHOW)
$file = FileOpen("ak.txt",1)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Button_word
            $read_input = GUICtrlRead($input_naam)
            FileWrite($file, "12" & $read_input & "34")
        Case $msg = $GUI_EVENT_CLOSE
            FileClose($file)
            ExitLoop
    EndSelect
WEnd

M23

Thanx!

That worked!!!

There are 10 kinds of people, those who understand me and those who don't.
Link to comment
Share on other sites

Hey

I just tested with the above code. It works perfectly well. It creates a file in C drive, named ak.txt. and writes 12*****34. **** represents i/p.

What exactly is the problem.

Is it creating the file or not. n if it is then what is it writing to the file.

Also plz tell me the version u r using

@Manjish

Sorry for Double posting but I just saw your post after I posted my reply,

I didn't know that it created ak.txt in C drive because my first script created ak.txt on the same folder with the script and I looked for ak.txt on the wrong place. Sorry for the misunderstanding.

There are 10 kinds of people, those who understand me and those who don't.
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...