DigDeep Posted December 16, 2015 Share Posted December 16, 2015 Hi,Can someone help here plz?When I click on Open File Button, instead of opening the file path in a new window, the file contents should show inside the Edit box I have created here.Just to show, I have created a text file on the Desktop as test.txt and saved the text as ABCD1234. When I click on Open File button, it should show the file contents "ABCD1234" as shown in the pic.#Region #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region $Form1 = GUICreate("Form1", 1476, 814, 192, 132) $Button1 = GUICtrlCreateButton("OPEN FILE", 600, 24, 251, 33) GUICtrlCreateEdit("", 40, 80, 1393, 713) GUISetState(@SW_SHOW) #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 OpenFile() EndSwitch WEnd Func OpenFile() $Path = @DesktopDir & "\Test.txt" ShellExecute($Path) EndFunc ;==>OpenFile Link to comment Share on other sites More sharing options...
Alex1986 Posted December 16, 2015 Share Posted December 16, 2015 Try This#Region #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region $Form1 = GUICreate("Form1", 600, 600, -1, -1) $Button1 = GUICtrlCreateButton("OPEN FILE", 200, 24, 251, 33) $edit = GUICtrlCreateEdit("", 40, 80, 500, 550) GUISetState(@SW_SHOW) #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetData($edit, OpenFile()) EndSwitch WEnd Func OpenFile() $Path = @DesktopDir & "\test.txt" Return FileRead($Path) EndFunc ;==>OpenFile Link to comment Share on other sites More sharing options...
DigDeep Posted December 17, 2015 Author Share Posted December 17, 2015 @Alex1986But I missed out to give the Input box on my previous one. I want to just click on the Input box which will open the Browse to folder menu. When selecting the file name it should show only the complete file path in the Input box (I don;t want to give a seperate Button for this). And when clicking on OPEN FILE button, it should display the file contents in the Edit menu.2 things here...1. When I open the below code, the Browse window opens Automatically. It should open only when I click on the INPUTBOX.2. I have found as per your above suggestion that if I change the filepath from .txt to .doc or .xls, it does not display the file contents. The way I wanted is, when I click on Open File, it should display the file contents in the same format the file is in. If it is word file it should display as the word format. If an excel file it should display the tables and text format inside excel. Could you please help here. Thanks expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <FileConstants.au3> #Region $Form1 = GUICreate("Form1", 600, 600, -1, -1) $Button1 = GUICtrlCreateButton("OPEN FILE", 328, 24, 196, 33) $Input1 = GUICtrlCreateInput("Input1", 64, 32, 209, 24) $edit = GUICtrlCreateEdit("", 40, 80, 500, 550) GUISetState(@SW_SHOW) #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case MouseClick($Input1) Browse() Case $Button1 GUICtrlSetData($edit, OpenFile()) EndSwitch WEnd Func OpenFile() $Path = @DesktopDir & "\Test.txt" Return FileRead($Path) EndFunc ;==>OpenFile Func Browse() ; Create a constant variable in Local scope of the message to display in FileOpenDialog. Local Const $sMessage = "Hold down Ctrl or Shift to choose multiple files." ; Display an open dialog to select a list of file(s). Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)", $FD_FILEMUSTEXIST + $FD_MULTISELECT) If @error Then ; Display the error message. ;MsgBox(0, "", "No file(s) were selected.") ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) Else ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog. $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF) ; Display the list of selected files. MsgBox(0, "", "You chose the following files:" & @CRLF & $sFileOpenDialog) EndIf EndFunc ;==>Browse Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now