AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Looping a range of dates (xxxx/xx/xx/ - xxxx/xx/xx) by month

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
kitaljevich



Joined: 04 Oct 2007
Posts: 11

PostPosted: Mon Aug 11, 2008 2:33 pm    Post subject: Looping a range of dates (xxxx/xx/xx/ - xxxx/xx/xx) by month Reply with quote

Hi there,

I'm writing a script that interfaces with a web database to pull data into a spreadsheet. Not an extremely difficult task, but I've run into a problem.

I threw up a GUI and inserted two MonthCal's, then stringsplit the output into the xxxx/xx/xx format the database requires. My challenge arises because the database will not load if there are too many results (usually if you request over a month's worth).

So essentially what I'm trying to do is let the user choose a range of dates, say from 2008/08/13 - 2008/11/13 then have the script break the range down into one month segments - then repeat.

I know I'm going to need counters and loops, but I just can't figure it out.


Any insight would be greatly appreciated Very Happy

Code:

Gui, Color, 6699CC
Gui, Add, MonthCal, x16 y102 w180 h160 vStartDate
Gui, Add, MonthCal, x256 y100 w180 h160 vEndDate
Gui, Add, Button, x246 y320 w90 h30 , Start
Gui, Add, Button, x346 y320 w90 h30 , Cancel
Gui, Add, Picture, x-260 y0 w716 h80 , C:\Documents and Settings\EKITALJE\Desktop\new_banner_E.gif
Gui, Add, GroupBox, x6 y82 w200 h190 +Center, Start Date
Gui, Add, GroupBox, x246 y80 w200 h190 +Center, End Date
;Gui, Add, Text,, Username:
;Gui, Add, Text,, Password:
Gui, Add, Edit, x78 y308 w120 h20 vUsername,
Gui, Add, Edit, x78 y338 w120 h20 vPassword,
Gui, Add, Text, x16 y310 w60 h20 , Username:
Gui, Add, Text, x16 y340 w60 h20 , Password:
Gui, Add, GroupBox, x6 y280 w200 h120 , Authentication
Gui, Add, Button, x136 y370 w60 h20 , Login
Gui, Show, x488 y159 h417 w454, LRM Data Download Tool
;Gui, Show, x779 y112 h354 w456,
Return


ButtonLogin:
gui, submit
cUsername = REMOVED
cPassword = REMOVED

If(Username == cUsername && Password == cPassword)
{
MsgBox , 64, Authentication, You are now logged in., 5
authentication := 1

Gui, Show
return
}


ButtonStart:
Gui, submit

if authentication <> 1
{
MsgBox, 16, Error, Unauthorized Access `n     Please Login, 5
gui, show
return
}
else
{
;
;gui, show
;return


StringMid, sYear, StartDate, 1, 4
;msgbox, %sYear%
StringMid, sMonth, StartDate, 5, 2
;msgbox, %sMonth%
StringMid, sDay, StartDate, 7, 2
;msgbox, %sDay%


StringMid, eYear, EndDate, 1, 4
;msgbox, %eYear%
StringMid, eMonth, EndDate, 5, 2
;msgbox, %eMonth%
StringMid, eDay, EndDate, 7, 2
;msgbox, %eDay%

correctStartDate = %sYear%/%sMonth%/%sDay%
msgbox, Start Date: %correctStartDate%

correctEndDate = %eYear%/%eMonth%/%eDay%
msgbox, End Date: %correctEndDate%

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Run "iexplore.exe" REMOVED
sleep, 5000

;;;;;;;;;;;;;;;;;;;;;;;;;;;;WEB LOGIN;;;;;;;;;;;;;;;;;;;;;;;;;;
send, %cUsername%
sleep, 400

send, {TAB}
sleep, 400

send, %cPassword%
sleep, 400

send, {TAB}
sleep, 50

send, {ENTER}
sleep, 2000


;;;;;;;;;;;;;;;;;;;;;;;;;;SELECTING DATE;;;;;;;;;;;;;;;;;;;;;;
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50
send, {TAB}
sleep, 50

send, {ENTER}
sleep, 2000

Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50

Send, {TAB}
sleep, 50
Send, {SPACE}
sleep, 50

Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50

Send, {SPACE}
sleep, 50

Send, {TAB}
sleep, 50
Send, {SPACE}
sleep, 50

Send, {TAB}
sleep, 50
Send, %correctStartDate%
sleep, 300

Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50

Send, %correctEndDate%
sleep, 300

Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50
Send, {TAB}
sleep, 50
Send, {SPACE}
sleep, 50
Send, {TAB}
sleep, 50
Send, {ENTER}
sleep, 7000




MouseClick, left , 100, 500 ;triggering window before copying
sleep, 40



;;;;;;;;;;;;;;;;;SELECT ALL AND COPY;;;;;;;;;;;;;;;;;;;;;;;;;;
Send, {ALTDOWN}{ALTUP}e
sleep, 20
Send, {DOWN}
sleep, 20
Send, {DOWN}
sleep, 20
Send, {DOWN}
sleep, 20
Send, {ENTER}
sleep, 200
send, ^c ;copy
sleep, 500
sleep, 1500



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EXCEL;;;;;;;;;;;;;;;;;;;;;;
Run excel.exe ;start excel
sleep, 2000

Send, {ALTDOWN}{ALTUP}e
sleep, 200
Send, {DOWN}
sleep, 200
Send, {DOWN}
sleep, 200
Send, {DOWN}
sleep, 200
Send, {DOWN}
sleep, 200
Send, {DOWN}
sleep, 200
Send, {ENTER}
sleep, 500
Send, {DOWN}
sleep, 400
Send, {DOWN}
sleep, 400
Send, {ENTER}
sleep, 500
Send, {RIGHT}
sleep, 500
Send, {LEFT}
sleep, 500


Loop, 40
{
send, {PGDN}
sleep, 10
}

sleep, 1500

WinActivate , LRM - Lookup Offering - Windows Internet Explorer, ;switching to LRM
sleep, 500
MouseClick, left , 100, 500 ;triggering window before copying
sleep, 40


}


x::ExitApp


ButtonCancel:
Kill:
exitapp
return


Back to top
View user's profile Send private message
Peter



Joined: 30 Dec 2005
Posts: 279

PostPosted: Mon Aug 11, 2008 10:31 pm    Post subject: Reply with quote

It was a bit more difficult then I thought , but I came up with this:
Code:
   Gui, Add, MonthCal, vStartDate, 20081122
   Gui, Add, MonthCal, x+10 vEndDate, 20090210
   Gui, add, button, gSplitMonths , Split in Months
   Gui, show, , Split in Months
return
SplitMonths:
   Gui, submit, nohide
   ThisDate := StartDate ,  IntervalList :=  ""
   Loop {               ; e.g. StartDate = 20081122
      ThisYear := SubStr(ThisDate, 1, 4) , ThisMonth := SubStr(ThisDate, 5, 2)
      NextYear := !mod(ThisMonth, 12) ? ThisYear + 1 : ThisYear
      NextMonth := "0" . (!mod(ThisMonth, 12) ? 1 : ThisMonth + 1)
      StringRight, NextMonth, NextMonth, 2   ; 20081122 -> 12
      NextDate := NextYear . NextMonth . "01"   ; 20081122 -> 20081201
      StopInterval := NextDate
      StopInterval += -1, d   ; 20081122 -> 20081130000000
      StopInterval := SubStr(StopInterval, 1, 8)
      if (StopInterval >= EndDate) {
         IntervalList = %IntervalList%|%ThisDate%,%EndDate%
         Break
      }else
         IntervalList = %IntervalList%|%ThisDate%,%StopInterval%

      ThisDate := NextDate
   }
   msgbox %StartDate% -> %EndDate% gives following month intervals:`n%IntervalList%
return
GuiClose:
   ExitApp
return
The code example will give following result:
Quote:
20081122 -> 20090210 gives following month intervals:
|20081122,20081130|20081201,20081231|20090101,20090131|20090201,20090210
Back to top
View user's profile Send private message
kitaljevich



Joined: 04 Oct 2007
Posts: 11

PostPosted: Tue Aug 12, 2008 4:59 pm    Post subject: Reply with quote

You sir, are a god.

I'll sub this in, and report on my findings.


Thank you so much!
Back to top
View user's profile Send private message
kitaljevich



Joined: 04 Oct 2007
Posts: 11

PostPosted: Tue Aug 12, 2008 5:38 pm    Post subject: Reply with quote

Is there any way to store each date that gets generated in IntervalList as its own variable?

I want to put in a loop that (depending on the total number of months) visits the database that many times and sends the variable (or rather string) of the next start date and next end date that is contained in IntervalList.

I know I might be able to stringsplit the value of IntervalList, and pull out the dates that way, but I'm not sure how to save the output in a way that would work. Maybe stringsplit IntervalList to output %startdate1% and %enddate1% followed by %startdate2% and %enddate2% etc...

That last paragraph was probably meaningless and useless, but w/e, I tried.


Well, really appreciate all the help!
-e
Back to top
View user's profile Send private message
Peter



Joined: 30 Dec 2005
Posts: 279

PostPosted: Tue Aug 12, 2008 8:29 pm    Post subject: Reply with quote

kitaljevich wrote:
Is there any way to store each date that gets generated in IntervalList as its own variable? I know I might be able to stringsplit the value of IntervalList...
If you look in StringSplit under the Related paragraph, you find as first Parsing Loop . Just read about Loops, and you will find your solution with the following example Wink
Code:
IntervalList := "|20081122,20081130|20081201,20081231|20090101,20090131|20090201,20090210"
Loop, parse, IntervalList, |
{
   If (A_index = 1)
      Continue

   Interval := A_index - 1
   Loop, parse, A_loopField, csv
   {
      if (A_index = 1)
         StartDate%Interval% := A_loopField
      if (A_index = 2)
         StopDate%Interval% := A_loopField
   }
}
Loop, %Interval% {
   MsgBox, % A_index . ": " . StartDate%A_index% . " -> " . StopDate%A_index%
}
Back to top
View user's profile Send private message
kitaljevich



Joined: 04 Oct 2007
Posts: 11

PostPosted: Thu Aug 14, 2008 1:19 pm    Post subject: Reply with quote

Worked great!

Got exactly the end-result I wanted, thanks so much for all the help!

-e
Back to top
View user's profile Send private message
nader
Guest





PostPosted: Wed Sep 24, 2008 5:13 pm    Post subject: Reply with quote

how to make in order to have a result every six months?

Code:
from 20000401 to 20010905

output:

20000401 , 20000630
20000701 , 20001231
20010101 , 20010630
20010701 , 20010905
Back to top
nader
Guest





PostPosted: Thu Sep 25, 2008 7:01 am    Post subject: Reply with quote

can someone help me please?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group