Solved

VB6 = Week of the year in TextBox

Posted on 2012-12-30
9
486 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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 46

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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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 46

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

820 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