Jump to content

Read File


 Share

Recommended Posts

How would you make a script that reads the text from a file and updates a gui input? I would also like to know how to make the input box so when text hits the border, it goes down one line instead of continuing. Help would be appreciated.

Thanks,

Aaron

Edited by killaz219
Link to comment
Share on other sites

$filename = "C:\boot.ini"
$txt = FileRead($filename, FileGetSize($filename))
GUICtrlSetData($ctrlid, $txt)

<{POST_SNAPBACK}>

That didnt work.. Let me give you a little something to work with
GUICreate("my gui", 449, 338, (@DesktopWidth - 449) / 2, (@DesktopHeight - 338) / 2, 0x04CF0000)
$Input_14 = GUICtrlCreateInput("Enter text here", 250, 20, 180, 160, 0x00200000)
$Button_17 = GUICtrlCreateButton("Text from File", 250, 290, 180, 40)

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = -3
         ExitLoop
      Case $msg = $button_17
         $file = FileOpenDialog ("Open what file?", @desktopdir, "Text files (*.txt)")
         $file2 = $file
         $file = FileOpen ($file2, 0)
         If $file = -1 Then
            MsgBox(0, "Error", "Unable to open file.")
            Exit
         EndIf
       While 1
          $chars = FileRead($file, FileGetSize($file))
          If @error = -1 Then ExitLoop
          GUICtrlSetData ($input_14, $chars)
       Wend
       FileClose($file)
    EndSelect
WEnd
Edited by killaz219
Link to comment
Share on other sites

( a ) You don't need to open the file since just calling fileread with the filename will open and close the file in the function call

( b ) You don't need to while or wend at all. You can say if NOT @error then ...

EDIT: try this:

GUICreate("my gui", 449, 338, (@DesktopWidth - 449) / 2, (@DesktopHeight - 338) / 2, 0x04CF0000)
$Input_14 = GUICtrlCreateEdit("Enter text here", 250, 20, 180, 160, 0x00200000)
$Button_17 = GUICtrlCreateButton("Text from File", 250, 290, 180, 40)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = -3
            ExitLoop
        Case $msg = $button_17
        $file = FileOpenDialog ("Open what file?", @desktopdir, "Text files (*.txt)")
        if not @error then
            $chars = FileRead($file, FileGetSize($file))
            GUICtrlSetData ($input_14, $chars)
        endif
   EndSelect
WEnd
Edited by this-is-me
Who else would I be?
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...