Link to home
Start Free TrialLog in
Avatar of OmegaJunior
OmegaJuniorFlag for United States of America

asked on

Eternal calender

reetings,
Imagine using either the VB-custom calender control or the Access custom calender control.  I need to know the week number of the first day of the year. Now, sometimes this number is 53
(this year), sometimes it is 52 (last year) and sometimes it is 1 (next year). But I don't want to ENTER the week number as a variable or parameter, I want some function to RETURN the
correct week number. Now the calender custom control believes the week number of the first day of the year is week number 1. The Access and VB routines calling the first day of the year
return the date or the day, provided that one enters the week number. What I believe to be looking for is some kind of eternal calender that can supply week numbers for every year, given a
week index number. (Implying the index number of a week does not equal the week number: the first week might be week 53 and so on.)
Imagine!
Avatar of perove
perove
Flag of Norway image

I dont understand, If you want a week number og the first day in a year why not use the format propery so it will be somthing like:

Format("01.01.1997","ww",vbMonday,vbFirstFullWeek)
not the extra parameters you can use to custom the way you want the week calculated.

This will give you the week of the 01.01 in any year you put in.

or..?
perove
WILL THIS DO  

 'Text1 holds your year e.g 1999,2000 etc
    Week = Format("01-01-" & CStr(Text1), "ww", , vbFirstFourDays)


Avatar of OmegaJunior

ASKER

Greetings, deighton and perove,

Both your comments and answers helped put me on the right track. In the end, the following code gave me what I needed to know:

Public Sub WeekNumber()

Dim intWeek As Integer
Dim bytAEVT As Byte
Dim strMsg As String

strMsg = "Year and week: " & vbCrLf

bytAEVT = 0
Do While bytAEVT < 6
  intWeek = Format("01-01-" & CStr(1996 + bytAEVT), "ww", vbMonday, vbFirstFourDays)
  strMsg = strMsg & CStr(1996 + bytAEVT) & vbTab & intWeek & vbCrLf
  bytAEVT = bytAEVT + 1
Loop

MsgBox strMsg

End Sub

For this code, I used pieces of both your proposals. Therefore, I have to reject deightons answer, and ask the experts-exchange administration to divide the points between the two of you. Thank you.

Imagine!
ASKER CERTIFIED SOLUTION
Avatar of linda101698
linda101698

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial