Welcome back. I hope someone is getting something out of all this, thanks for the great comments.
Moving on. In order to make this useable for everyone, and not just for ME (IE My Birthday!), we want to offer the user a way to change the birthday (Month/Day). To do this we want to add a button to the object that calls up a custom preferences window where the user can select the day/month for their birthday.
One thing that we will be changing here to the origional code is that we now need to use a month/day for the birthday not a "hard coded" date. The reason for using the month/day is so that it will "roll-over" to the next year when it loads. In order to make this work we are changing the top part of the code to:
Code: vbscript
- Dim BDate,BMonth,BDay
- Sub Object_OnScriptEnter
- BMonth = 11
- BDay = 20
- Call GetBDay
- Object.SetTimer 1, 1000
- End Sub
You will see that I added (2) more vars to the top so that they can be passed to all the other funtions.
Also added is the code to SET a default month/day. This will be changed in the coming parts to allow it to read this from an INI file. (I like INI's better than setting things in the REG, it is easier to debug later)
ADDED
BMonth = 11
BDay = 20
These setup the defaults
Also added is a call to "GetBDay" this function is shown here:
Code: vbscript
- Function GetBDay()
- BdayToday = False
- testDate = BMonth &"/" & BDay &"/" & year(now)
- s = DateDiff("s", Now, testdate)
- If s > 0 Then
- BDate = cdate(testdate)
- Else
- testDate = BMonth &"/" & BDay &"/" & (year(now)+1)
- BDate = cdate(testdate)
- End If
- d = DateDiff("d", Now, testdate)
- If d= 365 Then msgbox "HAPPY BIRTHDAY!!"
- End Function
The GetBDay Function above takes and "builds" a date from the supplied month/day + the current Year.
Code: vbscript
- testDate = BMonth &"/" & BDay &"/" & year(now)
It then checks to see if this date has already passed or if its still in the future.
Doing this via a check to see how many "seconds" have passed or will pass between NOW and the Date it made from the Month/Day.
If the # of seconds (s) is > 0 this means that the date has yet to come to pass, so keeping this year will work fine.
Else it sets the date to next year.
The CDate function converts a valid date and time expression to type Date, and returns the result.
I use this as a "test" for the date.
Code: vbscript
- s = DateDiff("s", Now, testdate)
- If s > 0 Then
- BDate = cdate(testdate)
- Else
- testDate = BMonth &"/" & BDay &"/" & (year(now)+1)
- BDate = cdate(testdate)
- End If
One other thing I check is to see if the # of days between NOW and the BDate is 365 (ie 1 year from today, so that makes today your birthday!). All it does for now is show a message box that says "HAPPY BIRTHDAY".
Code: vbscript
- d = DateDiff("d", Now, testdate)
- If d= 365 Then msgbox "HAPPY BIRTHDAY!!"
---- Adding the Preference Button ----

If you look at the image above you will see I have added a ( ) button next to the previous one we made to change the state to LARGE mode (from MINI). This button is a CLONE of the other button, but I changed the images to that circle. Again, all these images could change easily. From this button we will call up the Preferences window. One thing else that was changed was the TOOL TIP to show that your calling the pref's window.
In order to make this work we have to change the code for the "left buttin" function
Code: vbscript
- Function Object_OnLButtonUpEx(obj,x,y,dragged)
- If Not dragged Then
- Select Case obj.name
-
- Case "Birthday-CD-LargeModeBtn"
- desktopx.object("Birthday-CD-MiniBG").visible = False
- desktopx.object("Birthday-CD-LargeBG").visible = True
- Case "Birthday-CD-MiniModeBTN"
- desktopx.object("Birthday-CD-LargeBG").visible = False
- desktopx.object("Birthday-CD-MiniBG").visible = True
- Case "Birthday-CD-Mini-PrefsBTN"
- Call PrefsMenu()
- End Select
- End If
- End Function
All that was added here was the PrefsBTN part to call a function called PREFSMENU
The PREFSMENU Function is used to call up the preference window and set the month/day.
The code for that is here:
Code: vbscript
- Function PrefsMenu()
- Set frm = DesktopX.CreateForm
- frm.caption = "RSS Feeds"
- frm.AddPreference "B-Month"
- frm.Preference("B-Month").Type = "ComboList"
- For x = 1 To 12
- frm.Preference("B-Month").AddValue x
- Next
- frm.Preference("B-Month").DefaultValue = BMonth
- frm.Preference("B-Month").Caption = "Month"
- frm.AddPreference "B-Day"
- frm.Preference("B-Day").Type = "ComboList"
- For x = 1 To 31
- frm.Preference("B-Day").AddValue x
- Next
- frm.Preference("B-Day").DefaultValue = BDay
- frm.Preference("B-Day").Caption = "Day"
- If frm.prompt Then
- BMonth = frm.Preference("B-Month").value
- BDay = frm.Preference("B-Day").value
- Call GetBDay()
- End If
- End Function
This is not a really complicated code, but I will break it down here.
Code: vbscript
- Set frm = DesktopX.CreateForm
-- Create the Form for us.
Code: vbscript
- frm.caption = "RSS Feeds"
-- Caption for the Window
-- Sets the B-Month Drop down, sets the name, calls it as a Combolist, and then adds the values via a simple
-- look so that it will show 1-12 in the drop down
-- It also sets the "default" based on what the default BMonth is set to.
Code: vbscript
- frm.AddPreference "B-Month"
- frm.Preference("B-Month").Type = "ComboList"
- For x = 1 To 12
- frm.Preference("B-Month").AddValue x
- Next
- frm.Preference("B-Month").DefaultValue = BMonth
- frm.Preference("B-Month").Caption = "Month"
-
-- Same thing for the Day, only we make this 31, since we cant change this once the window is open there is no way
-- to interact with the previous drop down so we have to use the "MAX" days of 31, so it COULD be possible to
-- select a date that is invalid, we will have to add a check for that in the future.
Code: vbscript
- frm.AddPreference "B-Day"
- frm.Preference("B-Day").Type = "ComboList"
- For x = 1 To 31
- frm.Preference("B-Day").AddValue x
- Next
- frm.Preference("B-Day").DefaultValue = BDay
- frm.Preference("B-Day").Caption = "Day"
-- Once the user selects their settings and picks "OK" it moves on to the next section
-- If they hit Cancel it will ignor the next section
-- It sets the value of the vars to the ones the user selected.
-- HERE is where we would need to do some kind of check for a valid date. (Will look at that later)
Code: vbscript
- If frm.prompt Then
- BMonth = frm.Preference("B-Month").value
- BDay = frm.Preference("B-Day").value
- Call GetBDay()
- End If
-
This allows the user to pick a month/day and then it sets it. This is JUST until the gadget closes, because we are not saving this anywhere at this time. Will add that in the next step, as well as the check for a valid date.
Enjoy,
RomanDA