Solved

Eternal calender

Posted on 1999-01-08
4
316 Views
Last Modified: 2012-05-04
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!
0
Comment
Question by:OmegaJunior
4 Comments
 
LVL 9

Expert Comment

by:perove
ID: 1973037
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
0
 
LVL 18

Expert Comment

by:deighton
ID: 1973038
WILL THIS DO  

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


0
 
LVL 3

Author Comment

by:OmegaJunior
ID: 1973039
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!
0
 
LVL 7

Accepted Solution

by:
linda101698 earned 100 total points
ID: 1973040
I am posting the solution found by OmegaJunior so it can be saved in the previously asked questions.  I will add the points assigned to this question back to his account so he can post questions for the experts who helped him.

Linda Gardner
Customer Service @ Experts Exchange

 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

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now