This one is going to have a lot fo code but I am not going to go over it all line by line. What I will do is to cover each function in basics.
I will list ALL the new code here in one block, then go over each section one by one below it.
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
- Sub Object_OnScriptEnter
- 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
- End Sub
- Sub Object_OnScriptExit
- object.KillTimer 1
- End Sub
- Function SetMode(Mode)
- Select Case Mode
- Case "Mini"
- desktopx.object("Birthday-CD-LargeBG").visible = False
- desktopx.object("Birthday-CD-MiniBG").visible = True
- Call SetINIValue("Mode","Mini")
- Case "Large"
- desktopx.object("Birthday-CD-MiniBG").visible = False
- desktopx.object("Birthday-CD-LargeBG").visible = True
- Call SetINIValue("Mode","Large")
- End Select
- 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"
- Cakk SetMode("Large")
- Case "Birthday-CD-Mini-PrefsBTN"
- Call PrefsMenu()
-
- Case "Birthday-CD-Large-PrefsBTN"
- Call PrefsMenu()
- End Select
- End If
- End Function
- 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 SetINIValue("Month",BMonth)
- Call SetINIValue("Day",BDay)
- End If
- Call GetBDay()
- End Function
- Function GetBDay()
- BdayToday = False
- testDate = 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 = BMonth &"/" & BDay &"/" & (year(now)+1)
- BDate = cdate(testdate)
- End If
- d = DateDiff("d", Now, testdate)
- If d= 365 Then msgbox "HAPPY BIRTHDAY!!"
- desktopx.Object("Birthday-CD-Mini-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
- System.SimpleWrite fn, IniContents, 1
- End Function
- Function ReadINI()
- Call CheckForINI()
- fn = desktopx.ExecutableDirectory & 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 = desktopx.ExecutableDirectory & IniName
- System.SimpleWrite fn, IniContents, 1
- End Function
- Function CheckForINI()
- fn = desktopx.ExecutableDirectory & 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
I know its a lot of code but most of it is to read/write/create the INI file, its a group of functions that can be used over and over, I like to use this set because its simple, and VERY customizable, and much easier to not have to re-write code over and over.
---- PART 1 ---
INI File info and basic reading
Code: vbscript
- Sub Object_OnScriptEnter
- 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
We set the ININame to the name of the ini file we want to use, in this case "CommunityBDay.ini".
Then we call the ReadINI function (see later in this article). This loads all the ini values and then allows us to read/write these as needed. You can see the calls to ReadINIValue for each item in the ini file.
Next Lets cover the basic operation of the INI Functions.
Code: vbscript
- 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
- System.SimpleWrite fn, IniContents, 1
- End Function
WriteBlankINI - is used to create a blank (well it will have default values) INI file.
The first section is used to setup the defaults.
We clear the ini count, then we set the initial values for each item, in this case Month/Day/Mode.
Then it cycles thru these and writes them to the ini file.
Code: vbscript
- Function ReadINI()
- Call CheckForINI()
- fn = desktopx.ExecutableDirectory & 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
ReadINI - Reads the ini file loads them into a array to be used by the other functions.
Code: vbscript
- 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 = desktopx.ExecutableDirectory & IniName
- System.SimpleWrite fn, IniContents, 1
- End Function
WriteINI - Writes out the INI File info to the file you put in as the name at the top of the code.
Code: vbscript
- Function CheckForINI()
- fn = desktopx.ExecutableDirectory & 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
CheckForINI- Checks to see if the INI file exists, if it doesnt it calls the WriteBlankINI function to create the file with the defaults.
Code: vbscript
- Function ReadINIValue(Item)
- ReadINIValue = ""
- For x = 1 To INICnt
- If UCase(IniTitle(x)) = UCase(Item) Then temp = IniDetails(x)
- Next
- ReadINIValue = Temp
- End Function
ReadINIValue - Searches the array (created by the ReadINI function) for the ITEM you have asked it to find.
It returns the value of the ITEM. Its a wonderful piece of script that makes reading an INI file VERY simple!
Code: vbscript
- Function SetINIValue(Item,value)
- For x = 1 To INICnt
- If UCase(IniTitle(x)) = UCase(Item) Then IniDetails(x) = Value
- Next
- Call WriteINI()
- End Function
SetINIValue - Updates the Array with the item and value you send it, then it calls the WriteINI function to write out the updated INI file. Soooo smooth.
Code: vbscript
- Function SetMode(Mode)
- Select Case Mode
- Case "Mini"
- desktopx.object("Birthday-CD-LargeBG").visible = False
- desktopx.object("Birthday-CD-MiniBG").visible = True
- Call SetINIValue("Mode","Mini")
- Case "Large"
- desktopx.object("Birthday-CD-MiniBG").visible = False
- desktopx.object("Birthday-CD-LargeBG").visible = True
- Call SetINIValue("Mode","Large")
- End Select
- End Function
SetMode - Sets the visibility of the mini and large items. before this was in another location, im doing it here to make it so that you can change mode by one simple call. IE: Call SetMode("Mini").
This might be changed later to allow things to fade, or move around, who knows. Or it might just stay as is.
There are some other changes to the code to incorporate the INI file, like adding...
Code: vbscript
- 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
...to the Prefs Menu, this writes out the updated info to the INI file, as soon as you select it.
There are some other changes made, nothing major.
So far here is what works:
- Read the settins from an ini file
- update the ini file when changes are made
- change between mini and large mode
- pick a date from the pref's menu, by month/day
- check this date to see if its a valid date, if not go back to the pref's menu
- countdown to the above date
We are really close to a working BETA here now. Im not 100% sure what else needs added, but i am going to pass this around at this point to see what people want done. I think it will need to have some kind of way to make this work in other parts of the world, but im not 100% sure how to do that at this point.
Is anyone still out there?
RomanDA