Freedom1 Posted March 13, 2009 Share Posted March 13, 2009 Hello All, I need some help in GUI modification and redisplay. The application I'm in the process of developing is one that takes a text file and replaces keywords with data (dates, strings, etc.). I've designed the form with KODA. In particular I have a row of info containing description, from-date, to-date, and file-desc. What I want to do is when the user selects and modifies "Daily-1" from-date, the to-date changes to the from-date + 1 day and the file-desc becomes the from-date in the format "mmddyy". And finally, redisplay the GUI to show all changes. I also need to know how to set the Date Picker with a default date (variable - such as: today or first of month, last day of month, etc.). All of this has to be easier to do that what I'm thinking. Give me a jump start in the right direction. CODE#include <Date.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> Local $GUI, $Btn_COLORREF, $Btn_BGR, $Btn_RGB, $iMemo Dim $DTN_FIRST = -760 dim $DTN_DATETIMECHANGE Dim $Idx = 0 Dim $DataArray [100] Dim $ReplaceArray[20][2] Dim $ReplaceArrayMax = 20 Dim $InputData = "" #Region ### START Koda GUI section ### Form=c:\autoitscripts\reportsetupapp\frm098001.kxf $frm098001 = GUICreate("Update RRD Template File", 729, 553, 194, 123) $btnReplace = GUICtrlCreateButton("Replace", 632, 184, 65, 33, 0) $btnExit = GUICtrlCreateButton("&Exit", 632, 496, 65, 33, 0) $btnReset = GUICtrlCreateButton("Reset", 632, 139, 65, 33, 0) $btnSave = GUICtrlCreateButton("Save", 632, 224, 65, 33, 0) $lblMessage = GUICtrlCreateLabel("", 232, 355, 4, 4) $Group1 = GUICtrlCreateGroup("Parameters", 16, 344, 233, 193) $Param1 = GUICtrlCreateInput("", 93, 371, 137, 21) $Param2 = GUICtrlCreateInput("", 93, 402, 137, 21) $Param3 = GUICtrlCreateInput("", 93, 432, 137, 21) $Param4 = GUICtrlCreateInput("", 93, 463, 137, 21) $Param5 = GUICtrlCreateInput("", 93, 494, 137, 21) $Label9 = GUICtrlCreateLabel("Param 1:", 33, 375, 46, 17) $Label2 = GUICtrlCreateLabel("Param 2:", 33, 402, 46, 17) $Label10 = GUICtrlCreateLabel("Param 3:", 33, 436, 46, 17) $Label11 = GUICtrlCreateLabel("Param 4:", 33, 465, 46, 17) $Label12 = GUICtrlCreateLabel("Param 5:", 33, 496, 46, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Date Parameters", 16, 104, 593, 225) $Date1F = GUICtrlCreateDate("", 105, 146, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date1T = GUICtrlCreateDate("", 273, 146, 161, 25) $Date1Name = GUICtrlCreateInput("", 449, 146, 137, 21) $Date2F = GUICtrlCreateDate("", 105, 179, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date2T = GUICtrlCreateDate("", 273, 179, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date2Name = GUICtrlCreateInput("", 449, 179, 137, 21) $Date3F = GUICtrlCreateDate("", 105, 217, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date3T = GUICtrlCreateDate("", 273, 217, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date3Name = GUICtrlCreateInput("", 449, 217, 137, 21) $Date4F = GUICtrlCreateDate("", 105, 252, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date4T = GUICtrlCreateDate("", 273, 252, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date4Name = GUICtrlCreateInput("", 449, 252, 137, 21) $Date5F = GUICtrlCreateDate("", 105, 292, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date5T = GUICtrlCreateDate("", 273, 292, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date5Name = GUICtrlCreateInput("", 449, 292, 137, 21) $Label4 = GUICtrlCreateLabel("Daily-1:", 66, 150, 30, 17) $Label5 = GUICtrlCreateLabel("Daily-2:", 31, 187, 58, 17) $Label6 = GUICtrlCreateLabel("Daily-3:", 31, 221, 58, 17) $Label7 = GUICtrlCreateLabel("Monthly:", 31, 255, 58, 17) $Label8 = GUICtrlCreateLabel("Yearly:", 31, 287, 58, 17) $Label13 = GUICtrlCreateLabel("---- From Date ----", 140, 126, 83, 17) $Label14 = GUICtrlCreateLabel("---- Thru Date ----", 311, 126, 82, 17) $Label15 = GUICtrlCreateLabel("---- File Desc ----", 477, 126, 78, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("Files", 16, 8, 465, 81) $tbInputFile = GUICtrlCreateInput("", 84, 27, 329, 21) $tbOutputFile = GUICtrlCreateInput("", 84, 60, 329, 21) $Label1 = GUICtrlCreateLabel("Input File:", 31, 29, 50, 17) $Label3 = GUICtrlCreateLabel("Output File:", 23, 62, 58, 17) $btnInputFile = GUICtrlCreateButton("Browse", 419, 27, 49, 17, 0) $btnOutputFile = GUICtrlCreateButton("Browse", 419, 60, 49, 17, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY,"WM_Notify_Events") #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $nMsg = $btnInputFile Case $nMsg = $btnOutputFile Case $nMsg = $btnReplace ;Exit Case $nMsg = $btnSave ;Exit Case $nMsg = $Btn_RGB ;Exit Case $nMsg = $btnExit Exit EndSwitch WEnd MsgBox( 4096, "Pc Long format", _DateTimeFormat( _NowCalc(),1)) MsgBox( 4096, "Pc Short format", _DateTimeFormat( _NowCalc(),2)) $DataArray[1] = "This is a test of converting MDYRep to a new MDYRep value" $ReplaceArray[1][0] = "MDYRep" $ReplaceArray[1][1] = "02/15/2008" For $Idx = 1 to 1 $InputData = StringReplace($DataArray[$Idx], $ReplaceArray[1][0],$ReplaceArray[1][1]) $DataArray[$Idx] = $InputData msgbox(0,"Display of Search Results", $InputData) Next ; Load default replacement values Func LoadRepValues() $ReplaceArray[1][0] = "MDYRep" $ReplaceArray[2][0] = "MDYRep" $ReplaceArray[3][0] = "MDYRep" $ReplaceArray[4][0] = "MDYRep" $ReplaceArray[5][0] = "MDYRep" $ReplaceArray[6][0] = "MDYRep" $ReplaceArray[7][0] = "MDYRep" $ReplaceArray[8][0] = "MDYRep" $ReplaceArray[9][0] = "MDYRep" $ReplaceArray[10][0] = "MDYRep" $ReplaceArray[11][0] = "MDYRep" $ReplaceArray[12][0] = "MDYRep" $ReplaceArray[13][0] = "MDYRep" $ReplaceArray[14][0] = "MDYRep" $ReplaceArray[15][0] = "MDYRep" $ReplaceArray[16][0] = "MDYRep" $ReplaceArray[17][0] = "MDYRep" $ReplaceArray[18][0] = "MDYRep" $ReplaceArray[19][0] = "MDYRep" $ReplaceArray[20][0] = "MDYRep" EndFunc ; Load Keywords to use in search and replace Func LoadRepTable() $ReplaceArray[1][0] = "MDYRep" $ReplaceArray[2][0] = "MDYRep" $ReplaceArray[3][0] = "MDYRep" $ReplaceArray[4][0] = "MDYRep" $ReplaceArray[5][0] = "MDYRep" $ReplaceArray[6][0] = "MDYRep" $ReplaceArray[7][0] = "MDYRep" $ReplaceArray[8][0] = "MDYRep" $ReplaceArray[9][0] = "MDYRep" $ReplaceArray[10][0] = "MDYRep" $ReplaceArray[11][0] = "MDYRep" $ReplaceArray[12][0] = "MDYRep" $ReplaceArray[13][0] = "MDYRep" $ReplaceArray[14][0] = "MDYRep" $ReplaceArray[15][0] = "MDYRep" $ReplaceArray[16][0] = "MDYRep" $ReplaceArray[17][0] = "MDYRep" $ReplaceArray[18][0] = "MDYRep" $ReplaceArray[19][0] = "MDYRep" $ReplaceArray[20][0] = "MDYRep" EndFunc Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event Dim $DateCode = 0 dim $xx = 0 dim $yy ="12/31/2009" $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $event = $DTN_DATETIMECHANGE ConsoleWrite('changed' & @CRLF) $DateCode = GUICtrlRead(DllStructGetData($tagNMHDR, 2)) Select Case $DateCode = $Date1F GUICtrlSetData($Date1T, $DateCode) Case $DateCode = $Date2F Case $DateCode = $Date3F Case $DateCode = $Date4F Case $DateCode = $Date5F EndSelect EndSelect GUISetState(@SW_SHOW) $tagNMHDR = 0 $event = 0 $lParam = 0 EndFunc; #cs DTN_FIRST = (0 - 760), + DTN_DATETIMECHANGE = (DTN_FIRST + 1), + DTN_USERSTRINGA = (DTN_FIRST + 2), + DTN_WMKEYDOWNA = (DTN_FIRST + 3), + DTN_FORMATA = (DTN_FIRST + 4), + DTN_FORMATQUERYA = (DTN_FIRST + 5), + DTN_DROPDOWN = (DTN_FIRST + 6), + DTN_CLOSEUP = (DTN_FIRST + 7), + DTN_USERSTRINGW = (DTN_FIRST + 15), + DTN_WMKEYDOWNW = (DTN_FIRST + 16), + DTN_FORMATW = (DTN_FIRST + 17), + DTN_FORMATQUERYW = (DTN_FIRST + 18) #ce Thanks, Freedom1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 13, 2009 Moderators Share Posted March 13, 2009 (edited) Freedom1,Here is a solution to the "set Thru Date to +1" question. It uses a flag to show when the date in the first box has changed and then automatically 1) changes the second date & 2) writes the correct format date in the input. You can still adjust the second box, but if you change the first one again, you reset the second to +1 regardless of what it was set to beforehand. I have only implemented it for the Daily-1 series - I leave the others as "an exercise for the student"!As to setting default dates, you just set them when you use the GUICtrlCreateDate function. As you can see, leaving the first parameter blank (as in Daily-1) gives you the current date. I have set Daily-2 to the "First of the Month" and Daily-3 to "Last of the Month" as an example.As a bonus - all of the Thru dates are set to to Start + 1 when they are created. No extra charge!Play with this code and see if it does what you want:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <Date.au3> Local $GUI, $Btn_COLORREF, $Btn_BGR, $Btn_RGB, $iMemo Dim $DTN_FIRST = -760 ;Dim $DTN_DATETIMECHANGE Dim $Idx = 0 Dim $DataArray[100] Dim $ReplaceArray[20][2] Dim $ReplaceArrayMax = 20 Dim $InputData = "" Global Const $DTM_SETFORMAT_ = 0x1032 #Region ### START Koda GUI section ### Form=c:\autoitscripts\reportsetupapp\frm098001.kxf $frm098001 = GUICreate("Update RRD Template File", 729, 553, 194, 123) $btnReplace = GUICtrlCreateButton("Replace", 632, 184, 65, 33, 0) $btnExit = GUICtrlCreateButton("&Exit", 632, 496, 65, 33, 0) $btnReset = GUICtrlCreateButton("Reset", 632, 139, 65, 33, 0) $btnSave = GUICtrlCreateButton("Save", 632, 224, 65, 33, 0) $lblMessage = GUICtrlCreateLabel("", 232, 355, 4, 4) $Group1 = GUICtrlCreateGroup("Parameters", 16, 344, 233, 193) $Param1 = GUICtrlCreateInput("", 93, 371, 137, 21) $Param2 = GUICtrlCreateInput("", 93, 402, 137, 21) $Param3 = GUICtrlCreateInput("", 93, 432, 137, 21) $Param4 = GUICtrlCreateInput("", 93, 463, 137, 21) $Param5 = GUICtrlCreateInput("", 93, 494, 137, 21) $Label9 = GUICtrlCreateLabel("Param 1:", 33, 375, 46, 17) $Label2 = GUICtrlCreateLabel("Param 2:", 33, 402, 46, 17) $Label10 = GUICtrlCreateLabel("Param 3:", 33, 436, 46, 17) $Label11 = GUICtrlCreateLabel("Param 4:", 33, 465, 46, 17) $Label12 = GUICtrlCreateLabel("Param 5:", 33, 496, 46, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Date Parameters", 16, 104, 593, 225) ; Change 1T in W...W if 1F changes $Date1F = GUICtrlCreateDate("", 105, 146, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $TodayPlus1 = @YEAR & "/" & @MON & "/" & @MDAY + 1 $Date1T = GUICtrlCreateDate($TodayPlus1, 273, 146, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date1Name = GUICtrlCreateInput("", 449, 146, 137, 21) ; Set to First of Month $FoM = @YEAR & "/" & @MON & "/01" $Date2F = GUICtrlCreateDate($FoM, 105, 179, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $FoMPlus1 = _DateAdd("D", 1, $FoM) $Date2T = GUICtrlCreateDate($FoMPlus1, 273, 179, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date2Name = GUICtrlCreateInput("", 449, 179, 137, 21) ; Set to Last of Month $LD = _DateDaysInMonth(@YEAR, @MON) $LoM = @YEAR & "/" & @MON & "/" & $LD $Date3F = GUICtrlCreateDate($LoM, 105, 217, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $LoMPlus1 = _DateAdd("D", 1, $LoM) $Date3T = GUICtrlCreateDate($LoMPlus1, 273, 217, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date3Name = GUICtrlCreateInput("", 449, 217, 137, 21) $Date4F = GUICtrlCreateDate("", 105, 252, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date4T = GUICtrlCreateDate("", 273, 252, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date4Name = GUICtrlCreateInput("", 449, 252, 137, 21) $Date5F = GUICtrlCreateDate("", 105, 292, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date5T = GUICtrlCreateDate("", 273, 292, 161, 25) GUICtrlSendMsg(-1, 0x1005, 0, "") $Date5Name = GUICtrlCreateInput("", 449, 292, 137, 21) $Label4 = GUICtrlCreateLabel("Daily-1:", 66, 150, 30, 17) $Label5 = GUICtrlCreateLabel("Daily-2:", 31, 187, 58, 17) $Label6 = GUICtrlCreateLabel("Daily-3:", 31, 221, 58, 17) $Label7 = GUICtrlCreateLabel("Monthly:", 31, 255, 58, 17) $Label8 = GUICtrlCreateLabel("Yearly:", 31, 287, 58, 17) $Label13 = GUICtrlCreateLabel("---- From Date ----", 140, 126, 83, 17) $Label14 = GUICtrlCreateLabel("---- Thru Date ----", 311, 126, 82, 17) $Label15 = GUICtrlCreateLabel("---- File Desc ----", 477, 126, 78, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("Files", 16, 8, 465, 81) $tbInputFile = GUICtrlCreateInput("", 84, 27, 329, 21) $tbOutputFile = GUICtrlCreateInput("", 84, 60, 329, 21) $Label1 = GUICtrlCreateLabel("Input File:", 31, 29, 50, 17) $Label3 = GUICtrlCreateLabel("Output File:", 23, 62, 58, 17) $btnInputFile = GUICtrlCreateButton("Browse", 419, 27, 49, 17, 0) $btnOutputFile = GUICtrlCreateButton("Browse", 419, 60, 49, 17, 0) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) ;GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") #EndRegion ### END Koda GUI section ### $Date1_State = GUICtrlRead($Date1F) $Date1_State = GUICtrlRead($Date1F) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $nMsg = $btnInputFile Case $nMsg = $btnOutputFile Case $nMsg = $btnReplace ;Exit Case $nMsg = $btnSave ;Exit Case $nMsg = $Btn_RGB ;Exit Case $nMsg = $btnReset Case $nMsg = $btnExit Exit EndSwitch If GUICtrlRead($Date1F) <> $Date1_State Then $style = "yyyy/MM/dd" GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $style) GUICtrlSetData($Date1T, _DateAdd("D", 1, GUICtrlRead($Date1F))) $style = "MMddyy" GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $style) GUICtrlSetData($Date1Name, GUICtrlRead($Date1F)) $style = "dd MMMM yyyy" GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $style) $Date1_State = GUICtrlRead($Date1F) Endif WEnd MsgBox(4096, "Pc Long format", _DateTimeFormat(_NowCalc(), 1)) MsgBox(4096, "Pc Short format", _DateTimeFormat(_NowCalc(), 2)) $DataArray[1] = "This is a test of converting MDYRep to a new MDYRep value" $ReplaceArray[1][0] = "MDYRep" $ReplaceArray[1][1] = "02/15/2008" For $Idx = 1 To 1 $InputData = StringReplace($DataArray[$Idx], $ReplaceArray[1][0], $ReplaceArray[1][1]) $DataArray[$Idx] = $InputData MsgBox(0, "Display of Search Results", $InputData) Next ; Load default replacement values Func LoadRepValues() $ReplaceArray[1][0] = "MDYRep" $ReplaceArray[2][0] = "MDYRep" $ReplaceArray[3][0] = "MDYRep" $ReplaceArray[4][0] = "MDYRep" $ReplaceArray[5][0] = "MDYRep" $ReplaceArray[6][0] = "MDYRep" $ReplaceArray[7][0] = "MDYRep" $ReplaceArray[8][0] = "MDYRep" $ReplaceArray[9][0] = "MDYRep" $ReplaceArray[10][0] = "MDYRep" $ReplaceArray[11][0] = "MDYRep" $ReplaceArray[12][0] = "MDYRep" $ReplaceArray[13][0] = "MDYRep" $ReplaceArray[14][0] = "MDYRep" $ReplaceArray[15][0] = "MDYRep" $ReplaceArray[16][0] = "MDYRep" $ReplaceArray[17][0] = "MDYRep" $ReplaceArray[18][0] = "MDYRep" $ReplaceArray[19][0] = "MDYRep" $ReplaceArray[20][0] = "MDYRep" EndFunc ;==>LoadRepValues ; Load Keywords to use in search and replace Func LoadRepTable() $ReplaceArray[1][0] = "MDYRep" $ReplaceArray[2][0] = "MDYRep" $ReplaceArray[3][0] = "MDYRep" $ReplaceArray[4][0] = "MDYRep" $ReplaceArray[5][0] = "MDYRep" $ReplaceArray[6][0] = "MDYRep" $ReplaceArray[7][0] = "MDYRep" $ReplaceArray[8][0] = "MDYRep" $ReplaceArray[9][0] = "MDYRep" $ReplaceArray[10][0] = "MDYRep" $ReplaceArray[11][0] = "MDYRep" $ReplaceArray[12][0] = "MDYRep" $ReplaceArray[13][0] = "MDYRep" $ReplaceArray[14][0] = "MDYRep" $ReplaceArray[15][0] = "MDYRep" $ReplaceArray[16][0] = "MDYRep" $ReplaceArray[17][0] = "MDYRep" $ReplaceArray[18][0] = "MDYRep" $ReplaceArray[19][0] = "MDYRep" $ReplaceArray[20][0] = "MDYRep" EndFunc ;==>LoadRepTable Edited March 14, 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...
Freedom1 Posted March 14, 2009 Author Share Posted March 14, 2009 Freedom1,Here is a solution to the "set Thru Date to +1" question. It uses a flag to show when the date in the first box has changed and then automatically 1) changes the second date & 2) writes the correct format date in the input. You can still adjust the second box, but if you change the first one again, you reset the second to +1 regardless of what it was set to beforehand. I have only implemented it for the Daily-1 series - I leave the others as "an exercise for the student"!As to setting default dates, you just set them when you use the GUICtrlCreateDate function. As you can see, leaving the first parameter blank (as in Daily-1) gives you the current date. I have set Daily-2 to the "First of the Month" and Daily-3 to "Last of the Month" as an example.As a bonus - all of the Thru dates are set to to Start + 1 when they are created. No extra charge!Edited to add solution to default date question.Melba23,Your solution works beautifully! Just as I wanted it to. The coding is different than what I was thinking for sure, BUT YOURS WORKED!!!!!!!!!!Thank you so much for giving me the start that I needed to get this project moving along.Freedom1 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