Ok those that are still with me, I have refined the code some, modified the graphics, and i belive the only part left will be to put the graphic in that will display when today is their birthday. I have also added a "sound" object with a mp3 to play Happy Birthday. The buttons have been replaced with balloons to fit into the images better.
Here is the code:
Code: vbscript
- Dim BDate,BMonth,BDay
- '-- for INI FILE
- Dim IniName, IniCnt, IniTitle(100), IniDetails(100)
- Const ForWriting =2 : Const ForReading = 1 : Const ForAppending = 8
- '--- End INI
- Dim HappyBirthdayToday
- Dim INIPath
- Sub Object_OnScriptEnter
- Set objShell = CreateObject("WScript.Shell")
- INIPath = objShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal")
- Set objShell = nothing
- If right(INIPath,1) <> "\" Then INIPath = INIPath & "\"
- HappyBirthdayToday = False
- IniName = "CommunityBday.ini" '---- INI FILE NAME
- Call ReadINI() '-- Read INI File
- BMonth = ReadINIValue("Month") '--Set Initial Values
- BDay = ReadINIValue("Day")
- Call SetMode(ReadINIValue("Mode"))
- Call GetBDay
- Object.SetTimer 1, 1000
- End Sub
- Sub Object_OnTimer1
- CurTime = formatdatetime(now,3)
- i = DateDiff("s", Now, BDate)
- DaysLeft = i \ 86400
- i = i Mod 86400
- HoursLeft = i \ 3600
- i = i Mod 3600
- MinutesLeft = i \ 60
- i = i Mod 60
- SecondsLeft = i
- desktopx.Object("Birthday-CD-Large-days").text = DaysLeft
- desktopx.Object("Birthday-CD-Large-hrs").text = HoursLeft
- desktopx.Object("Birthday-CD-Large-min").text = MinutesLeft
- desktopx.Object("Birthday-CD-Large-sec").text = SecondsLeft
- Call GetBDay()
- End Sub
- Sub Object_OnScriptExit
- object.KillTimer 1
- End Sub
- Function SetMode(Mode)
- desktopx.Object("Birthday-CD-Flame-BG").visible = False
- Select Case Mode
- Case "Mini"
- desktopx.object("Birthday-CD-LargeBG").visible = False
- desktopx.object("Birthday-CD-MiniBG").visible = True
- FT = 48 : FL = 193
- Call SetINIValue("Mode","Mini")
- Case "Large"
- desktopx.object("Birthday-CD-MiniBG").visible = False
- desktopx.object("Birthday-CD-LargeBG").visible = True
- FT = 74 : FL = 204
- Call SetINIValue("Mode","Large")
- End Select
- desktopx.Object("Birthday-CD-Flame-BG").top = FT
- desktopx.Object("Birthday-CD-Flame-BG").left = FL
- desktopx.Object("Birthday-CD-Flame-BG").visible = True
- End Function
- Function Object_OnLButtonUpEx(obj,x,y,dragged)
- If Not dragged Then
- Select Case obj.name
-
- Case "Birthday-CD-LargeModeBtn"
- Call SetMode("Large")
- Case "Birthday-CD-MiniModeBTN"
- Call SetMode("Mini")
- Case "Birthday-CD-Mini-PrefsBTN"
- Call PrefsMenu()
-
- Case "Birthday-CD-Large-PrefsBTN"
- Call PrefsMenu()
- Case "HappyBirthday"
- Call ResetBirthday
- Case "Birthday-CD-Large-Close-BTN"
- widget.Close
-
- Case "Birthday-CD-Mini-Close-BTN"
- widget.Close
- End Select
- End If
- End Function
- Function PrefsMenu()
- Set frm = DesktopX.CreateForm
- frm.caption = "Community Birthday Countdown Prefs"
- 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 SetINIValue("Month",BMonth)
- Call SetINIValue("Day",BDay)
- End If
- Call GetBDay()
- End Function
- Function GetBDay()
- BdayToday = False
- testDate = FormatDate(BMonth &"/" & BDay &"/" & year(now))
- CheckDate = IsDate(testDate)
- If CheckDate <> True Then
- Msgbox "Date: " & testDate & vbnewline & "is Invalid" & vbnewline & "Please select a new date"
- Call PrefsMenu()
- Else
- s = DateDiff("s", Now, testdate)
- If s > 0 Then
- BDate = cdate(testdate)
- Else
- testDate = FormatDate(BMonth &"/" & BDay &"/" & (year(now)+1))
- BDate = cdate(testdate)
- End If
- d = DateDiff("d", Now, testdate)
- If d= 365 Then
- Call HappyBirthday
- Else
- HappyBirthdayToday = False
- End If
- desktopx.Object("Birthday-CD-Mini-BDate").text = BDate
- desktopx.Object("Birthday-CD-Large-BDate").text = BDate
- End If
- End Function
- '---INI FILE FUNCTIONS ----
- Function WriteBlankINI()
- '------------------ INI DEFAUTL VALUES HERE -----------------------
- IniCnt = 0
- IniCnt = IniCnt+ 1 : IniTitle(1) = "Mode" : IniDetails(1) = "Mini"
- IniCnt = IniCnt+ 1 : IniTitle(2) = "Month" : IniDetails(2) = 11
- IniCnt = IniCnt+ 1 : IniTitle(3) = "Day" : IniDetails(3) = 20
- ' The INI File is Stored in the Directory where the Program is run
- IniContents = ""
- For x = 1 To INICnt
- IniContents = IniContents & IniTitle(x) & "|" & IniDetails(x) & vbnewline
- Next
- 'fn = desktopx.ExecutableDirectory & IniName
- fn = INIPath & IniName
- System.SimpleWrite fn, IniContents, 1
- End Function
- Function ReadINI()
- Call CheckForINI()
- fn = INIPath & IniName
- TextList = System.SimpleRead(fn, 1)
- Lines = Split(TextList, Chr(10))
- IniCnt = 0
- For A = UBound(Lines) To LBound(Lines) Step -1
- If Len(Lines(A)) > 0 Then
- t = instr(Lines(A),"|")
- IniCnt = IniCnt + 1
- IniTitle(IniCnt) = left(Lines(A),t-1)
- IniDetails(IniCnt) = mid(Lines(A),t+1)
- l = len(IniDetails(IniCnt))
- IniDetails(IniCnt) = left(IniDetails(IniCnt),l-1)
- End If
- Next
- End Function
- Function WriteINI()
- ' The INI File is Stored in the Directory where the Program is run
- IniContents = ""
- For x = 1 To INICnt
- IniContents = IniContents & IniTitle(x) & "|" & IniDetails(x) & vbnewline
- Next
- fn = INIPath & IniName
- System.SimpleWrite fn, IniContents, 1
- End Function
- Function CheckForINI()
- 'fn = desktopx.ExecutableDirectory & IniName
- fn = INIPath & ININame
- Set filesys = CreateObject("Scripting.FileSystemObject")
- temp = filesys.FileExists(fn)
- path = filesys.GetAbsolutePathName(fn)
- If Not filesys.FileExists(fn) Then
- Call WriteBlankINI()
- End If
- End Function
- Function ReadINIValue(Item)
- ReadINIValue = ""
- For x = 1 To INICnt
- If UCase(IniTitle(x)) = UCase(Item) Then temp = IniDetails(x)
- Next
- ReadINIValue = Temp
- End Function
- Function SetINIValue(Item,value)
- For x = 1 To INICnt
- If UCase(IniTitle(x)) = UCase(Item) Then IniDetails(x) = Value
- Next
- Call WriteINI()
- End Function
- '---- FIX DATE FOR ANY LOCATION
- Function FormatDate(xdate)
- On Error Resume Next
- Dim ,s1,s2,sx
- If instr(xdate,"/") > 0 Then
- s1 = "/"
- ElseIf instr(xdate,".") > 0 Then
- s1 = "."
- ElseIf instr(xdate,"-") > 0 Then
- s1 = "-"
- End If
- Set objShell = CreateObject("WScript.Shell")
- = objShell.RegRead("HKEY_CURRENT_USER\Control Panel\International\sShortDate")
- s2 = objShell.RegRead("HKEY_CURRENT_USER\Control Panel\International\sDate")
- Set objShell = nothing
- sx = split(xdate,s1)
- If left(LCase( ),1) = "d" Then = sx(1)&s2&sx(0)&s2&sx(2) Else = sx(0)&s2&sx(1)&s2&sx(2)
- FormatDate = FormatDateTime( ,2)
- Set = nothing
- Set s1 = nothing
- Set s2 = nothing
- Set sx = nothing
- End Function
- Function HappyBirthday()
- If HappyBirthdayToday = False Then
- desktopx.object("Birthday-CD-PlaySong").state = "Play"
- desktopx.Object("Today").text = "WOOT!"
- HappyBirthdayToday = True
- desktopx.object("Birthday-CD-LargeBG").visible = False
- desktopx.object("Birthday-CD-MiniBG").visible = False
- desktopx.Object("Birthday-CD-Flame-BG").visible = False
- desktopx.Object("Birthday-CD-TimeBack").visible = False
- desktopx.object("HappyBirthday").visible = True
- msgbox "HAPPY BIRTHDAY!!" & vbnewline & "Click OK to stop music"
- desktopx.object("Birthday-CD-PlaySong").state = "Stop"
- End If
- End Function
- Function ResetBirthday()
- desktopx.Object("Today").text = " "
- desktopx.object("HappyBirthday").visible = False
- Call SetMode(ReadINIValue("Mode"))
- desktopx.Object("Birthday-CD-TimeBack").visible = True
- End Function
This section of code controls what happens when TODAY is the birthday.
Code: vbscript
- Function HappyBirthday()
- If HappyBirthdayToday = False Then
- desktopx.object("Birthday-CD-PlaySong").state = "Play"
- HappyBirthdayToday = True
- desktopx.object("Birthday-CD-LargeBG").visible = False
- desktopx.object("Birthday-CD-MiniBG").visible = False
- desktopx.Object("Birthday-CD-Flame-BG").visible = False
- desktopx.Object("Birthday-CD-TimeBack").visible = False
- desktopx.object("HappyBirthday").visible = True
- msgbox "HAPPY BIRTHDAY!!" & vbnewline & "Click OK to stop music"
- desktopx.object("Birthday-CD-PlaySong").state = "Stop"
- End If
- End Function
You can see in this line:
desktopx.object("Birthday-CD-PlaySong").state = "Play"
That it simply changes the STATE of the object that I assigned the MP3 to. This allows you to play the song "on command".
If left alone it will continue to play, so I added a MSGBOX to tell the person Happy Birthday and to STOP the playback of the song.
I also use the IF at the begining to stop this from showing every time the timer ticks off. You can see that inside the code it adds HappyBirthdayToday = True so that the next time it will not show. This is RESET back in the CheckBDay Code here:
Code: vbscript
- If d= 365 Then
- Call HappyBirthday
- Else
- HappyBirthdayToday = False
- End If
This allows this to be reset the next day so that it will work again in 365 days (as if anyone's pc will be working no-stop for 1 year.. LOL)
The gadget is about done, I will post a comment with the link when its 100% done. I will upload a WIDGET and a GADGET version so that if you want to take it apart and see how it works in more detail.
I hope that you have enjoyed this step into how a gadget is created, i know its not 100% perfect but it does allow you to get an idea on how this all works, and how to go about building your own.
If anyone has any other ones they would like me to create, please let me know. clock? calendar? weather? (ROFL).
RomanDA