Diana (Cda) Posted 15 hours ago Posted 15 hours ago (edited) I've cobbled together over time, from kind forum helpers here, the following type of date picker that works extremely well for me. Thank you to all who provide the valuable help here! But I don't know how to incorporate a way for user input to choose out of several extensions, i.e., .doc, .txt, .xls, or .xlt, etc. Here is the code in question to add the radio button to, if at all possible ... expandcollapse popup(less the UDF lines) ;========================================================================= Global $GUIboxTitle = "POSTS (+PATH/-EXT)" ;------------------------------------------------------------------------- ; don't change this year format here below; it is what is displayed in box Global $DateFormat = "yyMMdd.ddd" ;------------------------------------------------------------------------- $BoxIcon = $DatePickerIcon_HOME $FolderYearName = "" ;------------------------------------------------------------------------- ;$Button1_Text = "Create folder and send date to clipboard ..." $Button1_Text = "Send above date to the clipboard ..." ;------------------------------------------------------------------------- ; where text is not needed in either Prefix or Suffix - i.e., before or after the date - then just leave blank by using "" (no text in between quotes). $DateNameText_PREFIX = @ScriptDir & "\P- " $DateNameText_SUFFIX = ".1- Q- _ _ _- " ;========================================================================= Global $sPath = "", $sDateParams ;Global $hGUI = GUICreate($GUIboxTitle, 325, 250, 325, 340) ; width, height, left, top (this determines size of entire GUI box) Global $hGUI = GUICreate($GUIboxTitle, 575, 250, 500, 375) ; width, height, left, top (this determines size of entire GUI box) Global $date = GUICtrlCreateDate("", 10, 10, 200, 20) ; calendar pulldown box GUICtrlSendMsg($date, 0x1032, 0, $DateFormat) ; $DTM_SETFORMAT Global $hLabel1 = GUICtrlCreateLabel("", 10, 50, 300, 20) Global $hLabel2 = GUICtrlCreateLabel("", 10, 80, 300, 20) Global $hLabel3 = GUICtrlCreateLabel("", 10, 110, 300, 20) Global $hLabel4 = GUICtrlCreateLabel("", 10, 140, 300, 20) ;Global $DateChooseButton = GUICtrlCreateButton("Create folder and send date to clipboard ...", 10, 200, 250, 30) ;Global $DateChooseButton = GUICtrlCreateButton("Create folder here (also sends date to clipboard) ...", 10, 200, 300, 30) ; left, top, width, height (location of button) Global $DateChooseButton = GUICtrlCreateButton($Button1_Text, 10, 200, 300, 30) ; left, top, width, height (location of button) ;Global $FolderChooseButton = GUICtrlCreateButton("Select folder", 10, 170, 250, 30) ;Global $FolderChooseButton = GUICtrlCreateButton("1. Select folder ...", 10, 170, 450, 30) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $sDateParams = _GetDate($date, $hLabel1) GUISetIcon($BoxIcon, 14) ; this changes the GUI icon in upper left-hand corner + GUI taskbar icon to your chosen one GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit ; Case $FolderChooseButton ; $sPath = FileSelectFolder("Select folder", "" , 7 , @DesktopDir, $hGUI) ; GUICtrlSetData($FolderChooseButton, "1. Path selected: ''" & $sPath & "''") Case $DateChooseButton ;================================================================================ $ChosenDateFormat = $DateNameText_PREFIX & $sDateParams & $DateNameText_SUFFIX ;================================================================================ ; $sDateParams = _GetDate($date, $hLabel1) ; ClipPut($sDateParams) ClipPut($ChosenDateFormat) SoundPlay($CameraSound) Sleep(1500) ; If FileExists($sPath) = 1 Then ; FileChangeDir($sPath) ; DirCreate(@ScriptDir & "\" & $ChosenDateFormat) ; EndIf ;------------------------------------------------------------- EndSwitch WEnd Func _GetDate($cDate, $clabel) ;============================================================= Local $parametersDate = GUICtrlRead($cDate) ;============================================================= ;use StringRight() to get the three character weekday abbrev. from the selected date. Local $sWkDay = StringRight($parametersDate, 3) ;get the two character weekday abbreviation from the three-character weekday abbreviation. Local $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", $sWkDay), 2) ;replace the three character weekday, with the two character weekday. $parametersDate = StringReplace($parametersDate, $sWkDay, $ShortDayMyFormat) GUICtrlSetData($clabel, "Chosen date above, formatted as: " & $parametersDate) Return $parametersDate ;------------------------------------------------------------- EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Switch DllStructGetData($tNMHDR, "IDFrom") Case $date Switch DllStructGetData($tNMHDR, "Code") Case $DTN_DATETIMECHANGE ; Sent by a date and time picker (DTP) control whenever a change occurs $sDateParams = _GetDate($date, $hLabel1) Return 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Any help in this regard is greatly appreciated! I've been adding this in manually all these years, but time to try to find a solution thanks to this forum! Edited 15 hours ago by Diana (Cda)
Nine Posted 12 hours ago Posted 12 hours ago (edited) I don't quite understand why you posted that code while your title and explanation are very different. Here something that we can work with : #include <GUIConstants.au3> #include <Constants.au3> Example() Func Example() Local $hGUI = GUICreate("Example", 300, 200) Local $aExt = ["Excel (*.xls)", "Word (*.doc)", "Text (*.txt)", "Excel XML (*.xlsx)", "Word XML (*.docx)"], $aCheck[UBound($aExt)] For $i = 0 To UBound($aExt) - 1 $aCheck[$i] = GUICtrlCreateCheckbox($aExt[$i], 10, 10 + ($i * 20), 120, 18) Next Local $idOpen = GUICtrlCreateButton("Select Files", 150, 10, 100, 25) GUISetState() Local $sSelect, $sFilter While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idOpen $sFilter = "" For $i = 0 To UBound($aCheck) - 1 If GUICtrlRead($aCheck[$i]) = $GUI_CHECKED Then $sFilter &= $aExt[$i] & "|" Next If Not $sFilter Then ContinueLoop MsgBox($MB_OK, "Error", "Please select at least one extension") $sSelect = FileOpenDialog("Select Files", @ScriptDir, $sFilter, $FD_FILEMUSTEXIST + $FD_MULTISELECT) If $sSelect Then ConsoleWrite($sSelect & @CRLF) EndSwitch WEnd EndFunc ;==>Example Edited 12 hours ago by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Trong Posted 11 hours ago Posted 11 hours ago Your description is confusing, I really like Koda Tool: expandcollapse popup#include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> #include <WindowsConstants.au3> #include <Clipboard.au3> #include <StaticConstants.au3> ; ---------- Prefix & Suffix ---------- Global $DateNameText_PREFIX = "XXX" Global $DateNameText_SUFFIX = "YYY" ; ---------- GUI ---------- $hGUI = GUICreate("Path Builder", 562, 267, 192, 125) GUICtrlCreateLabel("Choose extension:", 24, 8, 100, 20, $SS_CENTERIMAGE) $radio_doc = GUICtrlCreateRadio(".doc", 20, 45, 113, 17) GUICtrlSetState(-1, $GUI_CHECKED) $radio_txt = GUICtrlCreateRadio(".txt", 20, 70, 113, 17) $radio_xls = GUICtrlCreateRadio(".xls", 20, 95, 113, 17) GUICtrlCreateLabel("Select date:", 272, 4, 76, 28, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) $dtp = GUICtrlCreateDate("2025/11/21 01:06:58", 360, 5, 180, 25) GUICtrlCreateLabel("File name", 8, 123, 90, 20, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) $input_filename = GUICtrlCreateInput("", 116, 128, 224, 21) GUICtrlCreateLabel("Folder:", 4, 160, 90, 20, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) $input_folder = GUICtrlCreateInput(@ScriptDir, 116, 153, 228, 21) $btn_browse = GUICtrlCreateButton("...", 354, 153, 40, 25) $btn_build = GUICtrlCreateButton("Build Full Path", 0, 182, 552, 35) $lbl_result = GUICtrlCreateLabel("Full path will appear here...", 4, 224, 552, 30, $SS_CENTERIMAGE) GUICtrlCreateLabel("Prefix: DateNameText_PREFIX", 164, 88, 384, 20, $SS_CENTERIMAGE) $lbl_date = GUICtrlCreateLabel("Date:", 164, 44, 384, 20, $SS_CENTERIMAGE) $lbl_filename = GUICtrlCreateLabel("File Name:", 164, 64, 384, 20, $SS_CENTERIMAGE) GUICtrlCreateLabel("Suffix: DateNameText_SUFFIX", 164, 108, 384, 20, $SS_CENTERIMAGE) GUISetState(@SW_SHOW) ; ---------- MAIN LOOP ---------- While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $btn_browse _BrowseFolder() Case $btn_build _BuildPath() EndSwitch WEnd ; ---------- Folder browse ---------- Func _BrowseFolder() Local $current = GUICtrlRead($input_folder) If $current = "" Then $current = "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" ; This PC EndIf Local $folder = FileSelectFolder("Choose folder:", $current, 1) If Not @error Then GUICtrlSetData($input_folder, $folder) EndFunc ; ---------- Build full path ---------- Func _BuildPath() Local $folder = GUICtrlRead($input_folder) Local $name = GUICtrlRead($input_filename) If $folder = "" Then MsgBox(48,"Error","Folder cannot be empty!") Return EndIf If $name = "" Then MsgBox(48,"Error","File name cannot be empty!") Return EndIf ; Extension Local $ext = ".doc" If GUICtrlRead($radio_txt) = $GUI_CHECKED Then $ext = ".txt" If GUICtrlRead($radio_xls) = $GUI_CHECKED Then $ext = ".xls" ; Date sanitize Local $rawDate = GUICtrlRead($dtp) Local $safeDate = StringReplace($rawDate,"/","-") $safeDate = StringReplace($safeDate,"\","-") ; Update labels GUICtrlSetData($lbl_date,"Date: " & $safeDate) GUICtrlSetData($lbl_filename,"File Name: " & $name) ; Build final name Local $finalName = $DateNameText_PREFIX & $safeDate & " " & $name & " " & $DateNameText_SUFFIX & $ext Local $fullPath = $folder & "\" & $finalName ; Show result GUICtrlSetData($lbl_result,$fullPath) ; Copy to clipboard _ClipBoard_Open(0) _ClipBoard_SetData($fullPath) _ClipBoard_Close() EndFunc Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal
donnyh13 Posted 6 hours ago Posted 6 hours ago (edited) Hi @Diana (Cda) Here is two ways you could do it. I personally would prefer a ComboBox, as it would take less code to use. expandcollapse popup;========================================================================= Global $GUIboxTitle = "POSTS (+PATH/-EXT)" ;------------------------------------------------------------------------- ; don't change this year format here below; it is what is displayed in box Global $DateFormat = "yyMMdd.ddd" ;------------------------------------------------------------------------- $BoxIcon = $DatePickerIcon_HOME $FolderYearName = "" ;------------------------------------------------------------------------- ;$Button1_Text = "Create folder and send date to clipboard ..." $Button1_Text = "Send above date to the clipboard ..." ;------------------------------------------------------------------------- ; where text is not needed in either Prefix or Suffix - i.e., before or after the date - then just leave blank by using "" (no text in between quotes). $DateNameText_PREFIX = @ScriptDir & "\P- " $DateNameText_SUFFIX = ".1- Q- _ _ _- " ;========================================================================= Global $sPath = "", $sDateParams ;Global $hGUI = GUICreate($GUIboxTitle, 325, 250, 325, 340) ; width, height, left, top (this determines size of entire GUI box) Global $hGUI = GUICreate($GUIboxTitle, 575, 250, 500, 375) ; width, height, left, top (this determines size of entire GUI box) Global $date = GUICtrlCreateDate("", 10, 10, 200, 20) ; calendar pulldown box GUICtrlSendMsg($date, 0x1032, 0, $DateFormat) ; $DTM_SETFORMAT ; ======================= Using Combo GUICtrlCreateLabel("Pick an Extension", 310, 150, 150, 20) Global $extCombo = GUICtrlCreateCombo("", 310, 170, 200, 20) Global $sExtensions = ".doc|.txt|.xls|.xlt" GUICtrlSetData($extCombo, $sExtensions) ; Set the Combo data ; ======================== Using Radio GUICtrlCreateGroup("Pick an Extension", 300, 10, 250, 135); Start the Group Global $extRadio1 = GUICtrlCreateRadio(".docx", 310, 30, 50, 20) Global $extRadio2 = GUICtrlCreateRadio(".txt", 310, 60, 50, 20) Global $extRadio3 = GUICtrlCreateRadio(".xls", 310, 90, 50, 20) Global $extRadio4 = GUICtrlCreateRadio(".xlt", 310, 120, 50, 20) GUICtrlCreateGroup("", 0, 0, 1, 1); Close the Group GUICtrlSetState($extRadio1, $GUI_CHECKED) ; ======================== Global $hLabel1 = GUICtrlCreateLabel("", 10, 50, 300, 20) Global $hLabel2 = GUICtrlCreateLabel("", 10, 80, 300, 20) Global $hLabel3 = GUICtrlCreateLabel("", 10, 110, 300, 20) Global $hLabel4 = GUICtrlCreateLabel("", 10, 140, 300, 20) ;Global $DateChooseButton = GUICtrlCreateButton("Create folder and send date to clipboard ...", 10, 200, 250, 30) ;Global $DateChooseButton = GUICtrlCreateButton("Create folder here (also sends date to clipboard) ...", 10, 200, 300, 30) ; left, top, width, height (location of button) Global $DateChooseButton = GUICtrlCreateButton($Button1_Text, 10, 200, 300, 30) ; left, top, width, height (location of button) ;Global $FolderChooseButton = GUICtrlCreateButton("Select folder", 10, 170, 250, 30) ;Global $FolderChooseButton = GUICtrlCreateButton("1. Select folder ...", 10, 170, 450, 30) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $sDateParams = _GetDate($date, $hLabel1) GUISetIcon($BoxIcon, 14) ; this changes the GUI icon in upper left-hand corner + GUI taskbar icon to your chosen one GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit ; Case $FolderChooseButton ; $sPath = FileSelectFolder("Select folder", "" , 7 , @DesktopDir, $hGUI) ; GUICtrlSetData($FolderChooseButton, "1. Path selected: ''" & $sPath & "''") Case $DateChooseButton ;================================================================================ $ChosenDateFormat = $DateNameText_PREFIX & $sDateParams & $DateNameText_SUFFIX ;================================================================================ ; $sDateParams = _GetDate($date, $hLabel1) ; ClipPut($sDateParams) ClipPut($ChosenDateFormat) ;~ SoundPlay($CameraSound) Sleep(1500) ; If FileExists($sPath) = 1 Then ; FileChangeDir($sPath) ; DirCreate(@ScriptDir & "\" & $ChosenDateFormat) ; EndIf ;------------------------------------------------------------- ; ============= Using ComboBox Case $extCombo ConsoleWrite("Combo clicked -- Selection: " & GUICtrlRead($extCombo) & @CRLF) ; ================ Using Radio Case $extRadio1 ConsoleWrite("Radio1 clicked: " & GUICtrlRead($extRadio1, $GUI_READ_EXTENDED) & @CRLF) Case $extRadio2 ConsoleWrite("Radio2 clicked: " & GUICtrlRead($extRadio2, $GUI_READ_EXTENDED) & @CRLF) Case $extRadio3 ConsoleWrite("Radio3 clicked: " & GUICtrlRead($extRadio3, $GUI_READ_EXTENDED) & @CRLF) Case $extRadio4 ConsoleWrite("Radio4 clicked: " & GUICtrlRead($extRadio4, $GUI_READ_EXTENDED) & @CRLF) ;=================================== EndSwitch WEnd Func _GetDate($cDate, $clabel) ;============================================================= Local $parametersDate = GUICtrlRead($cDate) ;============================================================= ;use StringRight() to get the three character weekday abbrev. from the selected date. Local $sWkDay = StringRight($parametersDate, 3) ;get the two character weekday abbreviation from the three-character weekday abbreviation. Local $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", $sWkDay), 2) ;replace the three character weekday, with the two character weekday. $parametersDate = StringReplace($parametersDate, $sWkDay, $ShortDayMyFormat) GUICtrlSetData($clabel, "Chosen date above, formatted as: " & $parametersDate) Return $parametersDate ;------------------------------------------------------------- EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Switch DllStructGetData($tNMHDR, "IDFrom") Case $date Switch DllStructGetData($tNMHDR, "Code") Case $DTN_DATETIMECHANGE ; Sent by a date and time picker (DTP) control whenever a change occurs $sDateParams = _GetDate($date, $hLabel1) Return 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited 6 hours ago by donnyh13 LibreOffice UDF ; Scite4AutoIt Spell-Checker Using LibreOffice Spoiler "Life is chiefly made up, not of great sacrifices and wonderful achievements, but of little things. It is oftenest through the little things which seem so unworthy of notice that great good or evil is brought into our lives. It is through our failure to endure the tests that come to us in little things, that the habits are molded, the character misshaped; and when the greater tests come, they find us unready. Only by acting upon principle in the tests of daily life can we acquire power to stand firm and faithful in the most dangerous and most difficult positions."
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