jmp Posted October 5, 2021 Share Posted October 5, 2021 Its Possible to short my code ? expandcollapse popup#include <GUIConstantsEx.au3> #include <IE.au3> #include <MsgBoxConstants.au3> $oIE = _IEAttach ("webpage") Local $hGUI = GUICreate("Select Month", 200, 365) Local $January = GUICtrlCreateButton("1 - January", 0, 5, 200, 25) Local $February = GUICtrlCreateButton("2 - February", 0, 35, 200, 25) Local $March = GUICtrlCreateButton("3 - March", 0, 65, 200, 25) Local $April = GUICtrlCreateButton("4 - April", 0, 95, 200, 25) Local $May = GUICtrlCreateButton("5 - May", 0, 125, 200, 25) Local $June = GUICtrlCreateButton("6 - June", 0, 155, 200, 25) Local $July = GUICtrlCreateButton("7 - July", 0, 185, 200, 25) Local $August = GUICtrlCreateButton("8 - August", 0, 215, 200, 25) Local $September = GUICtrlCreateButton("9 - September", 0, 245, 200, 25) Local $October = GUICtrlCreateButton("10 - October", 0, 275, 200, 25) Local $November = GUICtrlCreateButton("11 - November", 0, 305, 200, 25) Local $December = GUICtrlCreateButton("12 - December", 0, 335, 200, 25) GUISetState(@SW_SHOW, $hGUI) Local $iPID = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $January _January() Exit Case $February _February() Exit Case $March _March() Exit Case $April _April() Exit Case $May _May() Exit Case $June _June() Case $July _July() Exit Case $August _August() Exit Case $September _September() Exit Case $October _October() Exit Case $November _November() Exit Case $December _December() Exit GUIDelete($hGUI) EndSwitch WEnd Func _January() Local $form0 = _IEGetObjById($oIE, "form3") Local $oSelect = _IEFormElementGetObjByName($form0, "MonthID") _IEFormElementOptionSelect($oSelect, "January", 1, "byText") $btnpay = _IEGetObjById($oIE,"btngo") _IEAction($btnpay,"click") _IELoadWait($oIE) EndFunc Func _February() Local $form0 = _IEGetObjById($oIE, "form3") Local $oSelect = _IEFormElementGetObjByName($form0, "MonthID") _IEFormElementOptionSelect($oSelect, "February", 1, "byText") $btnpay = _IEGetObjById($oIE,"btngo") _IEAction($btnpay,"click") _IELoadWait($oIE) EndFunc Func _March() Local $form0 = _IEGetObjById($oIE, "form3") Local $oSelect = _IEFormElementGetObjByName($form0, "MonthID") _IEFormElementOptionSelect($oSelect, "March", 1, "byText") $btnpay = _IEGetObjById($oIE,"btngo") _IEAction($btnpay,"click") _IELoadWait($oIE) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 5, 2021 Moderators Share Posted October 5, 2021 (edited) jmp, Why not use a combo instead of all the buttons? And pass the month as a parameter to a single function? M23 Edited October 5, 2021 by Melba23 Wrong button too soon! 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...
jmp Posted October 5, 2021 Author Share Posted October 5, 2021 (edited) 6 minutes ago, Melba23 said: jmp, Why not use a combo instead of all the buttons? M23 @Melba23 How to use combo? And how to pass the month as a parameter to a single function? Edited October 5, 2021 by jmp Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 5, 2021 Moderators Share Posted October 5, 2021 jmp, expandcollapse popup#include <GUIConstantsEx.au3> #include <IE.au3> #include <MsgBoxConstants.au3> ;$oIE = _IEAttach ("webpage") Local $hGUI = GUICreate("Select Month", 200, 365) Local $cCombo = GUICtrlCreateCombo("", 10, 10, 180, 20) GUICtrlSetData($cCombo, "1 - January|2 - February|3 - March|4 - April|5 - May|6 - June|" & _ "7 - July|8 - August|9 - September|10 - October|11 - November|12 - December") GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cCombo ; Extract the month name from the combo data Local $sMonth = StringRegExpReplace(GUICtrlRead($cCombo), "\d*\s-\s", "") ; Pass to the function _Month($sMonth) Exit EndSwitch WEnd Func _Month($sMonth) ; And here it is in the function ConsoleWrite($sMonth & @CRLF) ;Local $form0 = _IEGetObjById($oIE, "form3") ;Local $oSelect = _IEFormElementGetObjByName($form0, "MonthID") ;_IEFormElementOptionSelect($oSelect, $sMonth, 1, "byText") ; ready to insert here <<<<<<<<<<<<<<<<<<< ;$btnpay = _IEGetObjById($oIE,"btngo") ;_IEAction($btnpay,"click") ;_IELoadWait($oIE) EndFunc ;==>_Month All clear? 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...
BigDaddyO Posted October 5, 2021 Share Posted October 5, 2021 This is as short as I can make it #include <GUIConstantsEx.au3> #include <IE.au3> #include <MsgBoxConstants.au3> Global $oIE = _IEAttach ("webpage") Global $aMonth[12][2] = [[0, "January"], [0, "February"], [0, "March"], [0, "April"], [0, "May"], [0, "June"], [0, "July"], [0, "August"], [0, "September"], [0, "October"], [0, "November"], [0, "December"]] Local $hGUI = GUICreate("Select Month", 200, 365) For $b = 0 to UBound($aMonth) - 1 $aMonth[$b][0] = GUICtrlCreateButton($b + 1 & " - " & $aMonth[$b][1], 0, $b * 30, 200, 25) Next GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg() For $i = 0 to UBound($aMonth) - 1 If $iMsg = $aMonth[$i][0] Then _SelectMonth($aMonth[$i][1]) Next If $iMsg = $GUI_EVENT_CLOSE Then Exit WEnd Func _SelectMonth($sMonth) ConsoleWrite("About to select " & $sMonth & @CRLF) Local $form0 = _IEGetObjById($oIE, "form3") Local $oSelect = _IEFormElementGetObjByName($form0, "MonthID") _IEFormElementOptionSelect($oSelect, $sMonth, 1, "byText") $btnpay = _IEGetObjById($oIE,"btngo") _IEAction($btnpay,"click") _IELoadWait($oIE) EndFunc Xandy and Werty 2 Link to comment Share on other sites More sharing options...
jmp Posted October 5, 2021 Author Share Posted October 5, 2021 Thanks @Melba23 & @BigDaddyO Both are great ! @Melba23 I want to also add Year and Ok button in this and Run the Script when Ok Button Pressed Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 5, 2021 Moderators Share Posted October 5, 2021 jmp, Quote I want to also add Year So add another combo. Quote and Ok button in this and Run the Script when Ok Button Pressed So add a button and read the combos when the button is pressed rather than when the combos are changed. 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...
jmp Posted October 5, 2021 Author Share Posted October 5, 2021 2 minutes ago, Melba23 said: So add a button and read the combos when the button is pressed rather than when the combos are changed. @Melba23 Please give me an example. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 5, 2021 Moderators Share Posted October 5, 2021 jmp, No, you try and code something yourself based on what I have already given you. If it does not work we can discuss why. M23 sudeepjd and mLipok 2 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...
jmp Posted October 6, 2021 Author Share Posted October 6, 2021 (edited) @Melba23, @BigDaddyO Short my another code : #include<date.au3> $iMonName = 'December' $iMonNum = _ConvertMonth($iMonName) Local $PrevMonth = $iMonNum-1 if $PrevMonth=0 then $PrevMonth = 12 $iDays = _DateDaysInMonth( @YEAR,$PrevMonth) $fDate = StringFormat ( "%.2d" , _ConvertMonth($PrevMonth)) ;~ MsgBox(0, "", $fDate) MsgBox( 4096, "Return", String($iDays) & "/" & String( $fDate) & "/" & StringRight(@YEAR, 4)) MsgBox( 4096, "Return", String($iDays-1) & "/" & String( $fDate) & "/" & StringRight(@YEAR, 4)) Func _ConvertMonth($date) $date = StringReplace($date, 'January', '01') $date = StringReplace($date, 'February', '02') $date = StringReplace($date, 'March', '03') $date = StringReplace($date, 'April', '04') $date = StringReplace($date, 'May', '05') $date = StringReplace($date, 'Jun', '06') $date = StringReplace($date, 'July', '07') $date = StringReplace($date, 'August', '08') $date = StringReplace($date, 'September', '09') $date = StringReplace($date, 'October', '10') $date = StringReplace($date, 'November', '11') $date = StringReplace($date, 'December', '12') Return $date EndFunc $iMonName should be equal to Selected Month from Dropdown list in IE. <option selected="selected" value="0">--Select--</option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> Edited October 6, 2021 by jmp Added HTML Link to comment Share on other sites More sharing options...
funkey Posted October 6, 2021 Share Posted October 6, 2021 I would use GUICtrlCreateMonthCal for this. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Werty Posted October 6, 2021 Share Posted October 6, 2021 (edited) 15 hours ago, BigDaddyO said: This is as short as I can make it Slightly shorter... #include <GUIConstantsEx.au3> #include <IE.au3> #Include <Date.au3> #include <MsgBoxConstants.au3> Global $oIE = _IEAttach ("webpage"), $aMonth[12][2], $hGUI = GUICreate("Select Month", 200, 365) For $b = 0 to 11 $aMonth[$b][1] = _DateToMonth($b+1) $aMonth[$b][0] = GUICtrlCreateButton($b + 1 & " - " & $aMonth[$b][1], 0, $b * 30, 200, 25) Next GUISetState(@SW_SHOW, $hGUI) While 1 $iMsg = GUIGetMsg() For $i = 0 to 11 If $iMsg = $aMonth[$i][0] Then _SelectMonth($aMonth[$i][1]) Next If $iMsg = $GUI_EVENT_CLOSE Then Exit WEnd Func _SelectMonth($sMonth) ConsoleWrite("About to select " & $sMonth & @CRLF) _IEFormElementOptionSelect(_IEFormElementGetObjByName(_IEGetObjById($oIE, "form3"), "MonthID"), $sMonth, 1, "byText") _IEAction(_IEGetObjById($oIE,"btngo"),"click") _IELoadWait($oIE) EndFunc Edited October 6, 2021 by Werty Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
JockoDundee Posted October 6, 2021 Share Posted October 6, 2021 Slightlier still? #include <GUIConstantsEx.au3> #include <IE.au3> #Include <Date.au3> #include <MsgBoxConstants.au3> Global $oIE = _IEAttach ("webpage"), $aMonth[12][2], $hGUI = GUICreate("Select Month", 200, 365) For $b = 0 to 11 $aMonth[$b][1] = _DateToMonth($b+1) $aMonth[$b][0] = GUICtrlCreateButton($b + 1 & " - " & $aMonth[$b][1], 0, $b * 30, 200, 25) Next GUISetState(@SW_SHOW, $hGUI) Do $iMsg = GUIGetMsg() For $i = 0 to 11 If $iMsg = $aMonth[$i][0] Then _SelectMonth($aMonth[$i][1]) Next Until iMsg = $GUI_EVENT_CLOSE Func _SelectMonth($sMonth) ConsoleWrite("About to select " & $sMonth & @CRLF) _IEFormElementOptionSelect(_IEFormElementGetObjByName(_IEGetObjById($oIE, "form3"), "MonthID"), $sMonth, 1, "byText") _IEAction(_IEGetObjById($oIE,"btngo"),"click") _IELoadWait($oIE) EndFunc Skysnake 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
jmp Posted October 6, 2021 Author Share Posted October 6, 2021 @Werty @JockoDundee Can you short my another code : #include<date.au3> $iMonName = 'December' $iMonNum = _ConvertMonth($iMonName) Local $PrevMonth = $iMonNum-1 if $PrevMonth=0 then $PrevMonth = 12 $iDays = _DateDaysInMonth( @YEAR,$PrevMonth) $fDate = StringFormat ( "%.2d" , _ConvertMonth($PrevMonth)) ;~ MsgBox(0, "", $fDate) MsgBox( 4096, "Return", String($iDays) & "/" & String( $fDate) & "/" & StringRight(@YEAR, 4)) MsgBox( 4096, "Return", String($iDays-1) & "/" & String( $fDate) & "/" & StringRight(@YEAR, 4)) Func _ConvertMonth($date) $date = StringReplace($date, 'January', '01') $date = StringReplace($date, 'February', '02') $date = StringReplace($date, 'March', '03') $date = StringReplace($date, 'April', '04') $date = StringReplace($date, 'May', '05') $date = StringReplace($date, 'Jun', '06') $date = StringReplace($date, 'July', '07') $date = StringReplace($date, 'August', '08') $date = StringReplace($date, 'September', '09') $date = StringReplace($date, 'October', '10') $date = StringReplace($date, 'November', '11') $date = StringReplace($date, 'December', '12') Return $date EndFunc Link to comment Share on other sites More sharing options...
Werty Posted October 6, 2021 Share Posted October 6, 2021 (edited) 12 hours ago, JockoDundee said: Slightlier still? Yes... #include <IE.au3> #Include <Date.au3> Global $oIE = _IEAttach ("webpage"), $aMonth[12][2], $hGUI = GUICreate("Select Month", 200, 365) For $b = 0 to 11 $aMonth[$b][1] = _DateToMonth($b+1) $aMonth[$b][0] = GUICtrlCreateButton($b + 1 & " - " & $aMonth[$b][1], 0, $b * 30, 200, 25) Next GUISetState() Do $iMsg = GUIGetMsg() For $i = 0 to 11 If $iMsg = $aMonth[$i][0] Then _SelectMonth($aMonth[$i][1]) Next Until $iMsg = - 3 Func _SelectMonth($sMonth) ConsoleWrite("About to select " & $sMonth & @CRLF) _IEFormElementOptionSelect(_IEFormElementGetObjByName(_IEGetObjById($oIE, "form3"), "MonthID"), $sMonth, 1, "byText") _IEAction(_IEGetObjById($oIE,"btngo"),"click") _IELoadWait($oIE) EndFunc Edited October 6, 2021 by Werty fixed iMsg -> $Imsg Some guy's script + some other guy's script = my script! 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