AutoHotkey Community

It is currently May 27th, 2012, 11:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: MonthCal controls
PostPosted: May 2nd, 2010, 7:58 am 
Offline

Joined: April 6th, 2008, 5:37 am
Posts: 13
Trying to get a display calendar, that always shows a full year, Jan-Dec.
If I uncomment the first line, I get the current year, no problem. But trying to move years I fail. I'm missing something about how MonthCal works with GuiControl, I think?

Code:
yr := A_YYYY
GUI, Destroy
yrspan = %yr%0101-%yr%1231
MsgBox, %yrspan%`n%mocal%
; Gui, Add, MonthCal, W-4 R3 Multi vmocal, %yrspan%
Gui, Add, MonthCal, W-4 R3 Multi vmocal
Gui, Add, Button, Section, &Previous Year
Gui, Add, Button, ys, &Next Year
GuiControl,, vmocal, %yrspan%
Gui, Show, Autosize X20 yCenter
return

ButtonPreviousYear:
Gui, Submit, NoHide
StringSplit, Date, mocal, -
Date1 := Date1 - 10000
Date2 := Date2 - 10000
yrspan = %Date1%-%Date2%
yr := Date1 / 10000
MsgBox, %yrspan%`n%mocal%
GuiControl,, vmocal, %yr%0101-%yr%1231
GuiControl,, vmocal, %yrspan%
Gui, Show
return

ButtonNextYear:
Gui, Submit, NoHide
; yr := yr + 1
; yrspan = %yr%0101-%yr%1231
StringSplit, Date, mocal, -
Date1 := Date1 - 10000
Date2 := Date2 - 10000
yrspan = %Date1%-%Date2%
yr := Date1 / 10000
MsgBox, %yrspan%`n%mocal%
GuiControl,, vmocal, %yr%0101-%yr%1231
GuiControl,, vmocal, %yrspan%
Gui, Show
return

GuiClose:
ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2010, 9:24 am 
You have 2 problems that I see. First you are referencing the control with the incorrect associated variable name.
Code:
GuiControl,, vmocal, %yr%0101-%yr%1231
; should be
GuiControl,, mocal, %yr%0101-%yr%1231


Second, you cannot perform 'normal' math operations on date-time variables, they are not 'normal' numbers. The normal method for manipulating date-time vars is to use EnvAdd (+=) and EnvSub (-=). But those operators only allow add/subrtacting units from seconds to days. You can however, manipulate the date-time variable as a string.

This (tested) code fixes the first problem, and demonstrates one way to work with the year part of the date-time.
Code:
yr := A_YYYY
GUI, Destroy
yrspan = %yr%0101-%yr%1231
MsgBox, %yrspan%`n%mocal%
Gui, Add, MonthCal, W-4 R3 Multi vmocal
Gui, Add, Button, Section, &Previous Year
Gui, Add, Button, ys, &Next Year
GuiControl,, vmocal, %yrspan%
Gui, Show, Autosize X20 yCenter
return

ButtonPreviousYear:
Gui, Submit, NoHide
StringSplit, Date, mocal, -
Date1 := SubStr(date1,1,4) - 1
GuiControl,, mocal, %Date1%0101-%Date1%1231
return

ButtonNextYear:
Gui, Submit, NoHide
StringSplit, Date, mocal, -
Date1 := SubStr(date1,1,4) + 1
GuiControl,, mocal, %Date1%0101-%Date1%1231
return

GuiClose:
ExitApp

ps, works as expected for 'next' year, but 'previious' year always starts with December - I'll leave that to you to find out why and fix it. ;)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2010, 9:43 am 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Code:
#NoEnv
Gui, Add, MonthCal, W-4 R3 Multi vmocal, % A_YYYY
Gui, Add, Button, Section, &Previous Year
Gui, Add, Button, ys, &Next Year
Gui, Show, Autosize x20 yCenter, MonthCal
Return

ButtonPreviousYear:
Gui, Submit, NoHide
GuiControl,, mocal, % (SubStr(mocal, 1, 4) - 1) . "01"
Return

ButtonNextYear:
Gui, Submit, NoHide
GuiControl,, mocal, % (SubStr(mocal, 1, 4) + 1) . "12"
Return

GuiClose:
ExitApp

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2010, 9:20 pm 
Offline

Joined: April 6th, 2008, 5:37 am
Posts: 13
dater12 wrote:
You have 2 problems that I see. First you are referencing the control with the incorrect associated variable name.
Code:
GuiControl,, vmocal, %yr%0101-%yr%1231
; should be
GuiControl,, mocal, %yr%0101-%yr%1231



Aha!! Thanks for this, dater12! I hadn't used GuiControl before, and couldn't see the lack of v in the examples. GUI needs the v, GuiControl doesn't.

Quote:
Second, you cannot perform 'normal' math operations on date-time variables, they are not 'normal' numbers.


The StringSplit converted the dates to strings, and henceforth to normal numbers. That stuff mostly worked, once I fixed the first problem, just had to tweak the calculations a bit. Oh, and to use // instead of / to get an integer result.

Here's the code that does what I want.
Code:
yr := A_YYYY
GUI, Destroy
yrspan = %yr%0101-%yr%0101
; Gui, Add, MonthCal, W-4 R3 Multi vmocal, %yrspan%
Gui, Add, MonthCal, W-4 R3 Multi vmocal
Gui, Add, Button, Section, &Previous Year
Gui, Add, Button, ys, &Next Year
GuiControl,, mocal, %yrspan%
GuiControl,, mocal, %A_Now%
Gui, Show, Autosize X20 yCenter
return

ButtonPreviousYear:
Gui, Submit, NoHide
StringSplit, Date, mocal, -
Date1 := Date1 - 10000
Date2 := Date2 - 10000
yrspan = %Date1%-%Date2%
yr := Date1 // 10000
GuiControl,, mocal, %yr%0101-%yr%0101
GuiControl,, mocal, %yrspan%
Gui, Show
return

ButtonNextYear:
Gui, Submit, NoHide
; yr := yr + 1
; yrspan = %yr%0101-%yr%1231
StringSplit, Date, mocal, -
Date1 := Date1 + 10000
Date2 := Date2 + 10000
yrspan = %Date1%-%Date2%
yr := Date1 // 10000
GuiControl,, mocal, %yr%1231-%yr%1231
GuiControl,, mocal, %yrspan%
Gui, Show
return

GuiClose:
ExitApp


Now I can write the rest of the application, now that I have the calendar interface under control. Thanks again. And thanks to Nick for responding also, although I didn't make clear that I wanted to move the year of the selection along with the year displayed.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], bowen666, MSN [Bot], Yahoo [Bot] and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group