twelo Posted December 20, 2009 Share Posted December 20, 2009 i want to save file from my gui -> editbox here my save functionFunc _Save() $file_save = FileSaveDialog("Save...", @DesktopDir, "Text Files (*.txt) | All Files (*.*)", 18, "", $MyGUI) If @error then Return(0) If StringInStr($file_save, ".", 0, -1) Then $file_save = StringMid($file_save, 1, StringInStr($file_save, ".", 0, -1) - 1) If $file_save <> "" Then $read = GUICtrlRead($EditBox) FileWrite($file_save & ".txt", $read) EndIf EndFunc1. unicode issue: i can open, read, write unicode files & characters in editbox. but i can not save file with unicode characters. output comes like ????? ??? ????? how to save unicode characters ?2. overwrite issue: whenever it saves or overwrite existing files. it adds the new content at the end of old file content. like i open a file with content "123" written, i added "456" & save or overwrite then output comes like "123123456" how to fix it ?3. extension issue: my gui supports .txt & *.* extension. but when i save file with *.* without any extension. saved output file comes with txt extension. and when i remove .txt from "FileWrite($file_save & ".txt", $read)" then it always save files without any extension. how to fix it ?help Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 20, 2009 Moderators Share Posted December 20, 2009 twelo,I think the problems 1 & 2 would be solved if you used FileOpen to open the file in the correct mode before writing to it - go and read the Help file page for FileOpen to see what is available. Remember that you will then need to use the file handle in your FileWrite command, and that you must use FileClose afterwards to free the handle. As for problem 3, it looks as if you are getting exactly what you asked for:saved output file comes with txt extension and when i remove .txt from "FileWrite($file_save & ".txt", $read)" then it always save files without any extension.if you set the filename to be $file_save & ".txt", why would AutoIt save it without an extension? 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...
twelo Posted December 21, 2009 Author Share Posted December 21, 2009 if you set the filename to be $file_save & ".txt", why would AutoIt save it without an extension? M23in filesavedialog i assign filter ".txt" & "*.*" but without $file_save & ".txt" it always save without any extension & with $file_save & ".txt" it always save with .txt extensionhow to save both, mean .txt & any extension (*.*) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 21, 2009 Moderators Share Posted December 21, 2009 twelo,When you use the "Save" dialog, the file is not given the extension you select in the "Save as type" combo. All that does is to show the files which match that filter if you use the "Browse folders" feature. You have to specify the extension you want if you are saving a new file rather than overwriting a previous one. So if you want a .txt extension, you have to add it to the filename yourself. I agree this is not what you would immediately think will happen - but that is what the dialog actually does! Go and try it yourself. However, even if you added the .txt extension manually, you then run this line:If StringInStr($file_save, ".", 0, -1) Then $file_save = StringMid($file_save, 1, StringInStr($file_save, ".", 0, -1) - 1)which promptly removes the .txt extension from any filename which has it. So regardless of what you entered in the "Save" dialog, you now have NO extension. Finally you use this line:FileWrite($file_save & ".txt", $read)to add a .txt extension to the filename - and guess what, you get the filename with .txt extension regardless of what you selected in the "Save" dialog! The solution is very simple - add the extension you want when you use the "Save" dialog (because it will not do it for you as explained above) and just use the filename that is returned.$file_save = FileSaveDialog("Save...", @ScriptDir, "Text Files (*.txt) | All Files (*.*)", 18, "") If @error Then Exit FileWrite($file_save, "Test")Note that you do not need theIf $file_save <> ""check. Did you actually try to save a blank filename? You will find that the "Save" dialog will not let you! 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...
twelo Posted December 21, 2009 Author Share Posted December 21, 2009 When you use the "Save" dialog, the file is not given the extension you select in the "Save as type" combo. All that does is to show the files which match that filter if you use the "Browse folders" feature.now i understand, i was messing with all my codes to get extension with filter it sorted out with save(.txt) & save as(*.*) dialog (problem 3 solved)(problem 2 solved) used filewritetoline to save file from the 1st line.but i can't figure out unicode problem fileopen, fileclose, & filewrite commands will be use for this, but how ?what if we want to save directly from editbox without open any file ?and when i use fileopen to open files with UTF 16(32) mode, regular text files not shows correctly.and how to get filehandle & config it with filewrite command any example wud br gr8 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 21, 2009 Moderators Share Posted December 21, 2009 twelo,what if we want to save directly from editbox without open any file ?I believe you MUST use FileOpen to open the file in the correct file format if you want to save UniCode. And I do not believe you can alter the format with FileWrite - that is why FileOpen has the flags it does. 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...
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