Jump to content

Short My Code ?


jmp
 Share

Recommended Posts

Its Possible to short my code ?
 

#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

  • Moderators

jmp,

Why not use a combo instead of all the buttons? And pass the month as a parameter to a single function?

M23

Edited by Melba23
Wrong button too soon!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

jmp,

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@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 by jmp
Added HTML
Link to comment
Share on other sites

I would use GUICtrlCreateMonthCal for this.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

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 by Werty

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

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

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

@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

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

:D

Edited by Werty
fixed iMsg -> $Imsg

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...