Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6 = Week of the year in TextBox

Posted on 2012-12-30
9
Medium Priority
?
496 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 49

Assisted Solution

by:Martin Liss
Martin Liss earned 1000 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 1000 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 49

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

722 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