-
Apr 27th, 2006, 08:08 AM
#1
Thread Starter
Hyperactive Member
calculating Next Thursday....
Hello , Good Morning all,
I am trying to write a function that calculates next thursday (for next 6 months) function
if some one has some ideas can you please share?
thanks
nath
-
Apr 27th, 2006, 08:30 AM
#2
Re: calculating Next Thursday....
I don't really understand what you mean by 'for next 6 months'. here's a fucntion for getting the next day:
VB Code:
Private Sub Form_Load()
Debug.Print NextDate(vbThursday, Now)
End Sub
Private Function NextDate(ByVal iDay As VbDayOfWeek, ByVal dAfter As Date) As Date
Do
dAfter = DateAdd("d", 1, dAfter)
Loop Until Weekday(dAfter) = iDay
NextDate = dAfter
End Function
-
Apr 27th, 2006, 08:48 AM
#3
Fanatic Member
Re: calculating Next Thursday....
For the next 6 months (26 weeks):
VB Code:
Private Sub Command1_Click()
Dim dToday As Date
Dim iLoop As Long
dToday = NextDate(vbThursday, Now)
For iLoop = 1 To 26
Debug.Print dToday
dToday = dToday + 7
Next
End Sub
Private Function NextDate(ByVal iDay As VbDayOfWeek, ByVal dAfter As Date) As Date
Do
dAfter = DateAdd("d", 1, dAfter)
Loop Until Weekday(dAfter) = iDay
NextDate = dAfter
End Function
My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]
-
Apr 27th, 2006, 01:42 PM
#4
Hyperactive Member
Re: calculating Next Thursday....
Hi All
This thread interested me. I would like to add such text "Next Saturday will be:"
How I can make this?
Thx in advance
I know, I know, my English is bad, sorry .....
-
Apr 27th, 2006, 01:43 PM
#5
Re: calculating Next Thursday....
Try the function i posted, you can set the day that it looks for to any of the days of the weeks, ie:
VB Code:
Debug.Print NextDay(vbSaturday, Now)
-
Apr 27th, 2006, 01:44 PM
#6
Re: calculating Next Thursday....
Originally Posted by bushmobile
Try the function i posted, you can set the day that it looks for to any of the days of the weeks.
In fact, you could put a listbox on the form with all of the names of the week days in it, and just have the user make a selection, and pass the selection to bush's function.
-
Apr 27th, 2006, 01:55 PM
#7
Hyperactive Member
Re: calculating Next Thursday....
ok, I made like this:
VB Code:
Private Sub Command1_Click()
Label1.Caption = "Next Saturday will be:" & " " & NextDate(vbSaturday, Now) '<<< I separated text a bit
End Sub
Private Function NextDate(ByVal iDay As VbDayOfWeek, ByVal dAfter As Date) As Date
Do
dAfter = DateAdd("d", 1, dAfter)
Loop Until Weekday(dAfter) = iDay
NextDate = dAfter
End Function
I have small question,
how to throw out time ( I want to leave only date)?
thx
I know, I know, my English is bad, sorry .....
-
Apr 27th, 2006, 01:56 PM
#8
Re: calculating Next Thursday....
VB Code:
'replace Now with
Format(Now, "mm/dd/yyyy")
-
Apr 27th, 2006, 01:57 PM
#9
Re: calculating Next Thursday....
or:
VB Code:
Format$(NextDate(vbSaturday, Now), "dd/mm/yyyy")
-
Apr 27th, 2006, 02:13 PM
#10
Hyperactive Member
Re: calculating Next Thursday....
I made so first:
VB Code:
Private Sub Command1_Click()
Dim NewDate As Date
NewDate = Format(Now, "mm/dd/yyyy")
Label1.Caption = "Next Saturday will be:" & " " & NextDate(vbSaturday, NewDate)
End Sub
but realy I see, that Bush gave a pretty piece of code, and it will be better so
great thanks for both
I greet
Last edited by Tamgovb; Apr 28th, 2006 at 02:37 AM.
I know, I know, my English is bad, sorry .....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|