Sign in to follow this  
Followers 0
bobheart

Read from txt file and edit txt file

10 posts in this topic

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

Share this post


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:

Share this post


Link to post
Share on other sites

I see what your saying but I'm not sure where to put what you gave me to use .

Need a little help where it should go . thank you for the help .

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thank you kind sir . i think I understand now that I can see it . I jusy had to change one line and it saves the file now .

FileWrite('sometxt.txt',$text)

FileWrite('destination.txt',$text)

Share this post


Link to post
Share on other sites

Maybe you have to delete the old file before saving if you use the same filename or it will happend the new text to the old one.

Share this post


Link to post
Share on other sites

Yes I just saw that .. lol

I see if I can figure that out . if not I'll give a yell .

Share this post


Link to post
Share on other sites

I just did this and it seemsd to work fine is this ok ?

Case $msg = $button_1

FileDelete("sometxt.txt")

$text = GUIRead ($edit_1)

FileWrite('sometxt.txt',$text)

Share this post


Link to post
Share on other sites

It seems so.

Share this post


Link to post
Share on other sites

Thnk you for the help . I know I can be a pest , but I do try to make things work before I ask for help .

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