Solved

VB6 = Week of the year in TextBox

Posted on 2012-12-30
9
493 Views
Last Modified: 2013-01-06
Hello all

I'm trying to find a way to put in Text1 the week number if the year.

Ex:
Between Dec 30 2012 and January 5ft 2013, this =  Week 1
Between Jan 6 2012 and January 12 2013, this =  Week 2....


So when i load the form with my Text1, today, i would see 1 (Being week 1)

How can i do that.

Thanks again for your help
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 250 total points
ID: 38731270
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38731274
I think i fount it.but i just need to tweak it cause i have week 53 on today's date but when i look at my company calendar, it count today as week 1 for 2013


 Dim iNumberOfTheWeek As Integer
    iNumberOfTheWeek = DatePart("ww", Now())
    MsgBox iNumberOfTheWeek

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38731281
But if i do this, now i have week 1:

        Dim iNumberOfTheWeek As Integer
    iNumberOfTheWeek = DatePart("ww", Now() + 2)
    MsgBox iNumberOfTheWeek

Open in new window


weird.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Accepted Solution

by:
IrogSinta earned 250 total points
ID: 38731301
If you count the weeks from the beginning of the year, today is really the start of the 53rd week.  However, if you base it on a 52 week year, today is really Week 1 (the 53rd week and the 1st week overlap at times).  

So to tweak it, you need to add a conditional statement to return a "1" if the week is "53"
iNumberOfTheWeek = IIf(DatePart("ww", Now())=53, 1, DatePart("ww", Now()))
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38731304
You don't want to add 2 to Now() because you are looking up the week number for 2 days later which is Jan 1st.
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38731348
Hi again.

Thank you so much both of you, again
all work great now.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 38731404
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0
 
LVL 15

Expert Comment

by:eemit
ID: 38731540
Here is another, possibly the right way to obtain Week Of the Year

  'Syntax for DatePart:
  'DatePart (Interval, Date,  [FirstDayOfWeek, [FirstWeekOfYear]] )
  'The FirstWeekOfYear argument can have one of the following settings.
  '2 - Week that has at least four days in the new year (complies with ISO standard 8601, section 3.17)
  '1 - Week in which January 1 occurs (default)
  '0 - First week of year specified in system settings

  'iNumberOfTheWeek = DatePart("ww", Now(), vbMonday, 2)
  'MsgBox iNumberOfTheWeek

  'You can use GetLocaleInfo API to obtain FirstWeekOfYear Specifier
  iNumberOfTheWeek = DatePart("ww", Now(), vbMonday, GetMyLocaleInfo(LOCALE_IFIRSTWEEKOFYEAR))
  MsgBox iNumberOfTheWeek


Option Explicit
   
Private Declare Function GetLocaleInfo Lib "kernel32" _
   Alias "GetLocaleInfoA" (ByVal Locale As Long, _
   ByVal LCType As Long, ByVal lpLCData As String, _
   ByVal cchData As Long) As Long

Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
Private Const LOCALE_IFIRSTWEEKOFYEAR As Long = &H100D  'first week of year specifier

Private Function GetMyLocaleInfo( _
                    ByVal LCType As Long _
                    ) As String
                    
  Dim sReturn As String
  Dim iRet1 As Long
  Dim iRet2 As Long
  Dim lpLCDataVar As String
  Dim Pos As Integer
  Dim Locale As Long
   
  Locale = GetUserDefaultLCID()
  iRet1 = GetLocaleInfo(Locale, LCType, lpLCDataVar, 0)
   
  sReturn = String$(iRet1, 0)
  iRet2 = GetLocaleInfo(Locale, LCType, sReturn, iRet1)
  Pos = InStr(sReturn, Chr$(0))
  If Pos > 0 Then
     sReturn = Left$(sReturn, Pos - 1)
  End If
  
  GetMyLocaleInfo = sReturn
  
  Exit Function

End Function

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 38731694
Thanks eemit

This is also very good to know
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 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