Do you know an easy way to get the Week Number in Scada?
Hi Romain
I found this and that should be Ok to code in SCADA BASIC but I did not check.
If you assume that:
- week 1 starts on January 1st of a given year
- week n+1 starts 7 days after week n
For an arbitrary day (1..31) of a given month (1..12) and year, the SWN can be calculated by:
SWN( y, m, d ) = 1 + ( DP( y, m ) + d-1 ) / 7
where DP ("Days Passed") is given by:
DP( y, 1 ) = 0
DP( y, m+1 ) = DP( y, m ) + ML( y, m )
and ML ("Month Length") is defined as:
ML( y, 1 ) = 31
ML( y, 2 ) = 28 + LEAP( y )
ML( y, 3 ) = 31
ML( y, 4 ) = 30
ML( y, 5 ) = 31
ML( y, 6 ) = 30
ML( y, 7 ) = 31
ML( y, 8 ) = 31
ML( y, 9 ) = 30
ML( y, 10 ) = 31
ML( y, 11 ) = 30
ML( y, 12 ) = 31
and LEAP( y ) is defined as:
LEAP( y ) = ( y % 4 == 0 ) && ( ( y % 100 != 0 ) || ( y % 400 == 0 ) )
I vote for the VBA Format instruction
Sub test()
Dim sWeek As String
sWeek = Format(Now, "ww")
End Sub
Just take care on one point: the Format instruction has the following syntax:
Format(expression [,format [,firstdayofweek [,firstweekofyear]]])
So, you can keep the first day of week and first week of year by default or use your own:
The firstdayofweek argument has these settings:
Constant Value Description
vbUseSystem 0 Use NLS API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
The firstweekofyear argument has these settings:
Constant Value Description
vbUseSystem 0 Use NLS API setting.
vbFirstJan1 1 Start with week in which January 1 occurs (default).
vbFirstFourDays 2 Start with the first week that has at least four days in the year.
vbFirstFullWeek 3 Start with the first full week of the year.
Ahhh Mr VBA...
Romain asked specificaly for a SCADA BASIC solution.
But in VBA of course this is easier 😛
Thanks Manu I'll try it.
Thanks Niko, but in VBA there is a lot of source on the net, so it will be easier to find a solution 🙂


