Jump to content

Need help with Editing a file


Recommended Posts

Hi there.

A friend of mine sent me a link to this page some days ago and I really love AutoIT, well done :(

But this also means that I'm a total noob :(

Here is my problem: I've got a text file, that is opened by my program. The interior (a single line) is being displayed in an InputBox. This works fine but if I change it, the changes get only then saved when I quit the program, and this is somehow strange. I built in a Save button that should have the job to initiate the save process, but if I press it, the file gets saved empty and then when I close the program, the file is again saved, but then with the wished text of the InputBox.

Now what I want to have: I want the the content of the input box to get saved whenever I change it (so it's going to change "live"). If this is not possible, I would like to have a save button working so the saving process happens when pressing this button.

Now here's my code:

#include <GuiConstants.au3>

GUICreate("Ca3DE Compile Map Tool",512,384)

$file = FileOpen ( "mapname.txt", 0 )
$mapname_file = FileReadLine ( $file , 1 )


;Input-Box
$Edit_1 = GuiCtrlCreateInput($mapname_file, 13, 17, 150, 20)

;Buttons

$Button_2 = GuiCtrlCreateButton("Save", 180, 10, 100, 30)

; Labels
GuiCtrlCreateGroup("Map name", 5, 0, 166, 45)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
      Case $msg = $GUI_EVENT_CLOSE
       ;Destroy the GUI including the controls
         GUIDelete()
       ;Exit the script
         Exit
    Case $msg = $Button_2
        $file1 = FileOpen ( "mapname.txt","2")
        $content = GuiCtrlRead($Edit_1)
        $mapname_file = FileWrite($file1,$content)  
        
   ;Case Else
   ;;;
    EndSelect
WEnd

GUIDelete()

Exit

Can anybody please help mit with this? I'm looking forward on receiving your help and/or hint(s)

Link to post
Share on other sites

Hi there.

A friend of mine sent me a link to this page some days ago and I really love AutoIT, well done  :( 

But this also means that I'm a total noob  :(

Here is my problem: I've got a text file, that is opened by my program. The interior (a single line) is being displayed in an InputBox. This works fine but if I change it, the changes get only then saved when I quit the program, and this is somehow strange. I built in a Save button that should have the job to initiate the save process, but if I press it, the file gets saved empty and then when I close the program, the file is again saved, but then with the wished text of the InputBox.

Now what I want to have: I want the the content of the input box to  get saved whenever I change it (so it's going to change "live"). If this is not possible, I would like to have a save button working so the saving process happens when pressing this button.

Now here's my code:

#include <GuiConstants.au3>

GUICreate("Ca3DE Compile Map Tool",512,384)

$file = FileOpen ( "mapname.txt", 0 )
$mapname_file = FileReadLine ( $file , 1 )
;Input-Box
$Edit_1 = GuiCtrlCreateInput($mapname_file, 13, 17, 150, 20)

;Buttons

$Button_2 = GuiCtrlCreateButton("Save", 180, 10, 100, 30)

; Labels
GuiCtrlCreateGroup("Map name", 5, 0, 166, 45)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
      Case $msg = $GUI_EVENT_CLOSE
      ;Destroy the GUI including the controls
         GUIDelete()
      ;Exit the script
         Exit
    Case $msg = $Button_2
        $file1 = FileOpen ( "mapname.txt","2")
        $content = GuiCtrlRead($Edit_1)
        $mapname_file = FileWrite($file1,$content)  
        
  ;Case Else
  ;;;
    EndSelect
WEnd

GUIDelete()

Exit

Can anybody please help mit with this? I'm looking forward on receiving your help and/or hint(s)

<{POST_SNAPBACK}>

Modified your code and it works like a charm. You were trying to open the file twice, so it overwrote itself with a blank file. You have to close the file. Below is your working code.

#include <GuiConstants.au3>

GUICreate("Ca3DE Compile Map Tool",512,384)

$file = FileOpen ( "mapname.txt", 0 )
$mapname_file = FileReadLine ( $file , 1 )
FileClose($file);Added FileClose()


;Input-Box
$Edit_1 = GuiCtrlCreateInput($mapname_file, 13, 17, 150, 20)

;Buttons

$Button_2 = GuiCtrlCreateButton("Save", 180, 10, 100, 30)

; Labels
GuiCtrlCreateGroup("Map name", 5, 0, 166, 45)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
      Case $msg = $GUI_EVENT_CLOSE
      ;Destroy the GUI including the controls
         GUIDelete()
      ;Exit the script
         Exit
    Case $msg = $Button_2
        $file = FileOpen ( "mapname.txt","2")
        $content = GuiCtrlRead($Edit_1)
        $mapname_file = FileWrite($file,$content)
        FileClose($file);Added FileClose()
        
  ;Case Else
  ;;;
    EndSelect
WEnd

GUIDelete()

Exit

I hope that helps.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...