System Date

BlueDragon
08-31-2003, 09:37 PM
How do I read the system date and after a specified number of days, make something happen. Such as, I'm making an alarm program to remind myself to do certain things. I want a MsgBox every 10,20,500 etc. days. How do I do this? I want to have a text box for the number to input, and every whatever the number of days is, I want the msgbox at that point.

Squishy
08-31-2003, 09:41 PM
You can just calculate the time of the alarm using DateAdd, save it to a file or the registry, then check every hour or so with a Timer control to see if it matches the value of Now.

MikeJ
08-31-2003, 09:42 PM
You would need to look into the Now and DateDiff functions on MSDN. To save the dates that you want to check for, you might need to save them into a file and read it, checking if the date is today.

~Mike

BlueDragon
08-31-2003, 10:10 PM
Im wanting it to pop up every 10 days. I dont want to have to program every actual date it has to run on. It looks like DateDiff only checks specified dates.

Squishy
08-31-2003, 11:05 PM
Every ten days from when? You can use DateAdd to add ten days to any given date. Store that in a file, then, when the timer runs, check if the alarm date = Now(); if yes, use DateAdd to set the next run time and display the MessageBox.

gfleming
09-01-2003, 12:19 AM
Hi BlueDragon,

Hope this helps,


Private Sub Form_Load()

'declare variables
Dim NextDate As Date

'assigns setting value if it exists, vbNull if it doesn't
NextDate = GetSetting(appname:="MyApp", section:="Startup", _
Key:="NextDate", Default:=vbNull)


'if there is no registry value (first time run)
'this will assign the first "NextDate" (10 days from now)
If NextDate = vbNull Then
NextDate = Date + 10
SaveSetting "MyApp", "Startup", "NextDate", NextDate
End If

'recall NextDate value
NextDate = GetSetting(appname:="MyApp", section:="Startup", _
Key:="NextDate", Default:=vbNull)

'if it has been atleast 10 day
If NextDate <= Date Then
'DoPeriodicProceedure
End If

End Sub



You may want to split the code up into different subs, but the basis is here to understand what is going on.

How do I read the system date and after a specified number of days, make something happen. Such as, I'm making an alarm program to remind myself to do certain things. I want a MsgBox every 10,20,500 etc. days. How do I do this? I want to have a text box for the number to input, and every whatever the number of days is, I want the msgbox at that point.

BlueDragon
09-01-2003, 12:48 AM
Thank you gfleming.

That is exactly what I meant. I want it to happen every ten days, like I said, and thats what you provided me. A million thanks.

gfleming
09-01-2003, 12:51 AM
I just learnt about Registry files tonight from OnErrOr, just goes to show you how wonderful this site is.

Garth.

Thank you gfleming.

That is exactly what I meant. I want it to happen every ten days, like I said, and thats what you provided me. A million thanks.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum