jjump Posted November 27, 2009 Share Posted November 27, 2009 Hi, I am trying to make a script that will write the name of a file that is dropped into the input box.. This is what I have so far.. expandcollapse popup#include <file.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Write file name", 436, 230, 191, 117, Default, $WS_EX_ACCEPTFILES) GUISetBkColor(0x0A3B76) Global $Input1 = GUICtrlCreateInput("", 20, 100, 360, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW) _FileCreate("temp.txt") $txt = FileOpen("temp.txt", 1) ; Check if file opened for writing OK If $txt = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED $File = @GUI_DragFile Switch @GUI_DropId Case $Input1 FileWrite($txt, "$File" & @CRLF) EndSwitch EndSwitch WEnd This does not work, can anyone tell me why? Thanks! Ian Link to comment Share on other sites More sharing options...
exodius Posted November 27, 2009 Share Posted November 27, 2009 @GUI_DropId only works if you're in OnEvent mode: (Note: Because you're using FileOpen, you won't see anything added to the txt file until you close the window which will call FileClose) expandcollapse popup#include <file.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt ("GUIOnEventMode", 1) $Form1_1 = GUICreate("Write file name", 436, 230, 191, 117, Default, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_EVENT_CLOSE") GUISetOnEvent($GUI_EVENT_DROPPED, "_GUI_EVENT_DROPPED") GUISetBkColor(0x0A3B76) Global $Input1 = GUICtrlCreateInput("", 20, 100, 360, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW) _FileCreate("test.txt") $txt = FileOpen("test.txt", 1) ; Check if file opened for writing OK If $txt = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 Sleep (100) WEnd Func _GUI_EVENT_CLOSE() FileClose ($txt) Exit EndFunc Func _GUI_EVENT_DROPPED() $File = @GUI_DragFile Switch @GUI_DropId Case $Input1 FileWrite($txt, $File & @CRLF) EndSwitch EndFunc Link to comment Share on other sites More sharing options...
jjump Posted November 27, 2009 Author Share Posted November 27, 2009 Hi, Thank you so much for your reply! I tried that but it does not seem to work.. I also want it to write to the file without needing to close the gui.. I thought it would be like this: expandcollapse popup#include <file.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt ("GUIOnEventMode", 1) $Form1_1 = GUICreate("Write file name", 436, 230, 191, 117, Default, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_EVENT_CLOSE") GUISetOnEvent($GUI_EVENT_DROPPED, "_GUI_EVENT_DROPPED") GUISetBkColor(0x0A3B76) Global $Input1 = GUICtrlCreateInput("", 20, 100, 360, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW) _FileCreate("test.txt") $txt = FileOpen("test.txt", 1) ; Check if file opened for writing OK If $txt = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 Sleep (100) WEnd Func _GUI_EVENT_CLOSE() Exit EndFunc Func _GUI_EVENT_DROPPED() $File = @GUI_DragFile Switch @GUI_DropId Case $Input1 FileWrite($txt, $File & @CRLF) FileClose ($txt) EndSwitch EndFunc But that does not seem to work.. Any ideas? Ian Link to comment Share on other sites More sharing options...
exodius Posted November 27, 2009 Share Posted November 27, 2009 (edited) How about this? #include <file.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt ("GUIOnEventMode", 1) $Form1_1 = GUICreate("Write file name", 436, 230, 191, 117, Default, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_EVENT_CLOSE") GUISetOnEvent($GUI_EVENT_DROPPED, "_GUI_EVENT_DROPPED") GUISetBkColor(0x0A3B76) Global $Input1 = GUICtrlCreateInput("", 20, 100, 360, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW) While 1 Sleep (100) WEnd Func _GUI_EVENT_CLOSE() Exit EndFunc Func _GUI_EVENT_DROPPED() $File = @GUI_DragFile Switch @GUI_DropId Case $Input1 FileWriteLine("test.txt", $File) EndSwitch EndFunc Edited November 27, 2009 by exodius Link to comment Share on other sites More sharing options...
jjump Posted November 27, 2009 Author Share Posted November 27, 2009 Hi, Nope.. Still not writing to the file.. Really cannot see what the matter is! Ian Link to comment Share on other sites More sharing options...
exodius Posted November 27, 2009 Share Posted November 27, 2009 Does this line by itself do anything? FileWriteLine ("test.txt", "This is a test.") Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2009 Moderators Share Posted November 27, 2009 (edited) Hi, Just to say that exodius' script in Post #4 is working fine for me. M23 Edit: @GUI_DropId only works if you're in OnEvent modeI hate to disagree but the code works in MessageLoop mode too without problem: #include <file.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Write file name", 436, 230, 191, 117, Default, $WS_EX_ACCEPTFILES) GUISetBkColor(0x0A3B76) Global $Input1 = GUICtrlCreateInput("", 20, 100, 360, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED _GUI_EVENT_DROPPED() EndSwitch WEnd Func _GUI_EVENT_DROPPED() $File = @GUI_DragFile Switch @GUI_DropId Case $Input1 FileWriteLine("test.txt", $File) EndSwitch EndFunc Edited November 27, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
exodius Posted November 27, 2009 Share Posted November 27, 2009 I hate to disagree but the code works in MessageLoop mode too without problem: Fair enough, I misread the line "OnEvent functions are only called when the option GUIOnEventMode is set to 1 - when in this mode GUIGetMsg is NOT used at all." from GUISetOnEvent Link to comment Share on other sites More sharing options...
jjump Posted November 27, 2009 Author Share Posted November 27, 2009 Thanks for all your replies! Moved the script and ran it again, now working fine!! Ok, so, it now writes the whole file name including the directory etc.. Is there anyway of just writing the files name? Thanks! Ian Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2009 Moderators Share Posted November 27, 2009 jjump, Just do this: Func _GUI_EVENT_DROPPED() $File = @GUI_DragFile Switch @GUI_DropId Case $Input1 FileWriteLine("test.txt", StringRegExpReplace($File, "^.*\\", "")) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndSwitch EndFunc M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jjump Posted November 30, 2009 Author Share Posted November 30, 2009 Perfect!! Thank you so much for all your help!! Ian 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