Sign in to follow this  
Followers 0
killaz219

Read File

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



FileWriteLine

FileReadLine

Assign FileReadLine to a variable then print the variable in the GUI.

Share this post


Link to post
Share on other sites

FileWriteLine

FileReadLine

Assign FileReadLine to a variable then print the variable in the GUI.

<{POST_SNAPBACK}>

I've tried that, but I want a more experienced person (like this-is-me, valik, etc.) to give me a sample code, or better support.

Share this post


Link to post
Share on other sites

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


Who else would I be?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

$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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

( 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?

Share this post


Link to post
Share on other sites

Nice! Thank you so much.

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