Jump to content

Better way to do this?


Recommended Posts

Hi all. I was just curious is there is another way to write this code, a better way. Like, do this in less commands, or work it from another angle? Thanks to everyone's help on arrays, I was able to make this more managable already.

All this script does, is poll the user, then drag and drop according to the input from the user. It is based on a month calendar in ACT! database, so there are seven days in the week, and five rows (like a month calendar).

Thanks in Advance

Global $x_coord[7] = [1045,1080, 1115, 1150, 1185, 1220, 1255];
Global $y_coord[5] = [120,135, 150, 165, 180];

$number_to_move = InputBox ("How many Contacts to move over?", "How many Contacts to move over?")
$day_of_week = InputBox ("Day of the week?", "Day of the week?")
$row = InputBox ("Row?", "Row? 1, 2, 3, 4, 5?")


If $day_of_week = "M" Then  $x_coord = $x_coord[0]
If $day_of_week = "T" Then  $x_coord = $x_coord[1]
If $day_of_week = "W" Then  $x_coord = $x_coord[2]
If $day_of_week = "Th" Then $x_coord = $x_coord[3]
If $day_of_week = "F" Then $x_coord = $x_coord[4]
If $day_of_week = "Sat" Then $x_coord = $x_coord[5]
If $day_of_week = "Sun" Then $x_coord = $x_coord[6]
If $row = 1 Then $y_coord = $y_coord[0]
If $row = 2 Then $y_coord = $y_coord[1]
If $row = 3 Then $y_coord = $y_coord[2]
If $row = 4 Then $y_coord = $y_coord[3]
If $row = 5 Then $y_coord = $y_coord[4]

$i = 0
While $i < $number_to_move

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("ACT! - [Mike - Calendar]","")
If Not WinActive("ACT! - [Mike - Calendar]","") Then WinActivate("ACT! - [Mike - Calendar]","")
WinWaitActive("ACT! - [Mike - Calendar]","")
MouseMove($x_coord,200)
MouseDown("left")
sleep (300)
MouseMove($x_coord, $y_coord) ; New Date 879-841 = 38
sleep (100)
MouseUp("left")
Sleep(1000)
$i = $i + 1
WEnd
Link to comment
Share on other sites

You could try this for starters. Hope this helps.

Global $x_coord[7] = [1045,1080, 1115, 1150, 1185, 1220, 1255];
Global $y_coord[5] = [120,135, 150, 165, 180];

$number_to_move = InputBox ("How many Contacts to move over?", "How many Contacts to move over?")
$day_of_week = InputBox ("Day of the week?", "Day of the week?")
$row = InputBox ("Row?", "Row? 1, 2, 3, 4, 5?")

;change this segment


$days[7] = ["M","T","W","Th","F","Sat","Sun"]

For $i = 0 to 6
    If $days[$i] == $day_of_week Then
        $x_coord = $x_coord[$i]
    EndIf
Next

$y_coord = $y_coord[ $row - 1 ]

;my changes end here

$i = 0
While $i < $number_to_move

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("ACT! - [Mike - Calendar]","")
If Not WinActive("ACT! - [Mike - Calendar]","") Then WinActivate("ACT! - [Mike - Calendar]","")
WinWaitActive("ACT! - [Mike - Calendar]","")
MouseMove($x_coord,200)
MouseDown("left")
sleep (300)
MouseMove($x_coord, $y_coord) ; New Date 879-841 = 38
sleep (100)
MouseUp("left")
Sleep(1000)
$i = $i + 1
WEnd

Also, you probably want some error checking on the day of the week and the row inputs. that ways invalid input wont crash your program.

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

Sorry if this just complicates things, but I added a GUI to constrain the values that can be entered and added some data validation. I also took out the x and y arrays by using the chosen values to calculate the values that came from the array.

Maybe not useful to you on this project, but an indication of what is possible.

#include <GUIConstants.au3>
$DaysOfWeek = "Mon|Tue|Wed|Thu|Fri|Sat|Sun"
$DaysOfWeekA = StringSplit($DaysOfWeek, "|")

; == GUI generated with Koda ==
$UserInput = GUICreate("Move Parameters", 310, 163, 192, 125)
; Contacts
GUICtrlCreateLabel("How many Contacts to move over?", 24, 8, 170, 17)
$Contacts = GUICtrlCreateInput("", 208, 8, 73, 21, -1, $WS_EX_CLIENTEDGE)
; Day of Week
GUICtrlCreateLabel("Day of Week:", 120, 40, 70, 17, $SS_RIGHTJUST)
$DaysCombo = GUICtrlCreateCombo("", 208, 40, 73, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData($DaysCombo, $DaysOfWeek, "Mon")
; Row
GUICtrlCreateLabel("Row:", 160, 72, 29, 17, $SS_RIGHTJUST)
$RowCombo = GUICtrlCreateCombo("", 208, 72, 73, 21, $CBS_DROPDOWNLIST)
GUICtrlSetData($RowCombo, "1|2|3|4|5", "1")
; OK and Cancel buttons
$OKButton = GUICtrlCreateButton("OK", 208, 120, 65, 25, $BS_DEFPUSHBUTTON)
$CancelButton = GUICtrlCreateButton("Cancel", 112, 120, 65, 25)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE or $msg = $CancelButton
        Exit
    Case $msg = $OKButton
        If Not( (GUICtrlRead($Contacts) + 0) > 0) Then
            MsgBox(0, "Invalid Data", "Please enter a number for the Contacts.")
        Else
            $number_to_move = GUICtrlRead($Contacts)
            For $i = 1 to $DaysOfWeekA[0]
                If GUICtrlRead($DaysCombo) = $DaysOfWeekA[$i] Then
                    $x_coord = 1045 + 35 * ($i - 1)
                EndIf
            Next
            $y_coord = 120 + 15 *(GUICtrlRead($RowCombo) - 1)
            ExitLoop
        EndIf
    Case Else
        ;;;;;;;
    EndSelect
WEnd
GUIDelete()

MsgBox(0, "Test", "Number to move : " & $number_to_move & @LF & "$x_coord : " & $x_coord & @LF & "$y_coord : " & $y_coord)
; My changes end here

$i = 0
While $i < $number_to_move

    Opt("WinWaitDelay",100)
    Opt("WinTitleMatchMode",4)
    Opt("WinDetectHiddenText",1)
    Opt("MouseCoordMode",0)
    WinWait("ACT! - [Mike - Calendar]","")
    If Not WinActive("ACT! - [Mike - Calendar]","") Then WinActivate("ACT! - [Mike - Calendar]","")
    WinWaitActive("ACT! - [Mike - Calendar]","")
    MouseMove($x_coord,200)
    MouseDown("left")
    sleep (300)
    MouseMove($x_coord, $y_coord) ; New Date 879-841 = 38
    sleep (100)
    MouseUp("left")
    Sleep(1000)
    $i = $i + 1
WEnd
BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

Sorry if this just complicates things, but I added a GUI to constrain the values that can be entered and added some data validation. I also took out the x and y arrays by using the chosen values to calculate the values that came from the array.

Maybe not useful to you on this project, but an indication of what is possible.

Actually, I really liked both of your inputs. Don just taught me a new way to look at arrays, and loops, that will be very helpful with a lot of other scripts I currently have. And your script helps me bypass the error checking. I really appreciate the help.

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...