Jump to content

Read from txt file and edit txt file


Recommended Posts

Could someone help me with this ? I don't know how to make it read from a file and how I can edit the txt when it is in the editbox and save it back to the file .

#cs - ### Generated by AutoBuilder 0.4 -- do not modify ###
394 206
0   1   0   0   0   1   0   0   0   0   0   0   0   0   1   0   
tab $tab_1  Tab 1   10  30  260 150 0   0   
tabitem $tabitem_1  Tabitem 1   0   0   0   0   0   0   
tabitem $tabitem_2  Tabitem 2   0   0   0   0   0   0   
edit    $edit_1 Edit 1  20  60  230 110 0   0   
tabitem     -99 -99 1   1   
button  $button_1   Button 1    300 100 70  20  0   0   
#ce - ### End of Dump ###

;Script generated by AutoBuilder 0.4


Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
GuiCreate("MyGUI", 392,201,(@DesktopWidth-392)/2, (@DesktopHeight-201)/2 , 0x04CF0000)
 $file = FileOpen("sometxt.txt", 0)

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

FileClose($file)
$tab_1 = GUISetControl("tab", "Tab 1", 10, 30, 260, 150)
$tabitem_1 = GUISetControl("tabitem", "Tabitem 1", 0, 0, 0, 0)
$tabitem_2 = GUISetControl("tabitem", "Tabitem 2", 0, 0, 0, 0)
    $edit_1 = GUISetControl("edit", "Edit 1", 20, 60, 230, 110)
   $button_1 = GUISetControl("button", "Save", 300, 100, 70, 20)
$tab_close = GUISetControl("tabitem","",-99,-99,1,1) ;close tab



GuiShow()

While 1
    sleep(100)
    $msg = GuiMsg(0)
    Select
    Case $msg = -3
        Exit
    Case $msg = 1
       ;;;
    Case $msg = $tab_1
       ;;;
    Case $msg = $tabitem_1
       ;;;
    Case $msg = $tabitem_2
       ;;;
    Case $msg = $edit_1
    FileRead =("sometxt.txt")
    Case $msg = $button_1
          ;;
    EndSelect
WEnd
Exit
Link to post
Share on other sites

I didn't test, but your Select/Case seems well structurated.

So you just need to use

$text = FileRead('sometxt.txt',FileGetSize('sometxt.txt'))

And use

GUIWrite ( $edit_1 ,0 ,$text )

for seeing the text

and finally use

$text = GUIRead ($edit_1)

FileWrite('destination.txt',$text)

for saving.

Hope it helps, but I guess it is not what you meant... :ph34r:

Link to post
Share on other sites

This will help, I hope.

As you can see the file is read when you click on any of the tabs. And the edit control reset (the first line uses a '' to remove old text)

When you press Save you create the file.

Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
GuiCreate("MyGUI", 392,201,(@DesktopWidth-392)/2, (@DesktopHeight-201)/2 , 0x04CF0000)
$file = FileOpen("sometxt.txt", 0)

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

FileClose($file)
$tab_1 = GUISetControl("tab", "Tab 1", 10, 30, 260, 150)
$tabitem_1 = GUISetControl("tabitem", "Tabitem 1", 0, 0, 0, 0)
$tabitem_2 = GUISetControl("tabitem", "Tabitem 2", 0, 0, 0, 0)
    $edit_1 = GUISetControl("edit", "Edit 1", 20, 60, 230, 110)
   $button_1 = GUISetControl("button", "Save", 300, 100, 70, 20)
$tab_close = GUISetControl("tabitem","",-99,-99,1,1);close tab



GuiShow()

While 1

    sleep(100)
    $msg = GuiMsg(0)
;   tooltip($msg & @lf & @lf & '$tab_1 = '& $tab_1 & @lf & '$tabitem_1 = ' & $tabitem_1 & @lf & '$tabitem_2 = ' & $tabitem_2 & @lf & '    $edit_1 = ' & $edit_1 & @lf &'   $button_1 = ' & $button_1 & @lf &'$tab_close = ' & $tab_close ) 
;Uncomment this line if you want to see the $msg values
;and maybe understand better where put code.;)
    Select
    Case $msg = -3
        Exit
    Case $msg = 1
    ;;;
    Case $msg = $tab_1
       $text = FileRead('sometxt.txt',FileGetSize('sometxt.txt'))
       GUIWrite ( $edit_1 ,0 ,'' )
       GUIWrite ( $edit_1 ,0 ,$text )
    Case $msg = $tabitem_1
    ;;;
    Case $msg = $tabitem_2
    ;;;
    Case $msg = $edit_1
    ;;;
    Case $msg = $button_1
       $text = GUIRead ($edit_1)
       FileWrite('destination.txt',$text)
    EndSelect
WEnd
Exit
Edited by ezzetabi
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...