Private sub button7_click (byval sender as system. object, byval e as system. eventargs) handles button7.click msgbox ("range:" & getweekperiod (Me. monthid. text, me. weeks. text) (0) & "& getweekperiod (Me. monthid. text, me. weeks. text) (1) end sub private function getweekperiod (byval monthid as string, byval curweeks as integer) as date () dim totalweeks as integer dim y, M as string y = monthid. substring (0, 4) M = monthid. substring (4) dim firstdayofmonth as date = new datetime (Y, M, 1) dim lastdayofmonth as date = new datetime (Y, M, date. daysinmonth (Y, m) dim D as date = firstdayofmonth dim edweek (1) as date dim ed (0) as date dim J as int16 for I as int16 = 0 to date. daysinmonth (Y, m)-1 if D. dayofweek = dayofweek. saturday then redim preserve ed (j) Ed (j) = d j = J + 1 if J = curweeks then if D. adddays (-6) <firstdayofmonth then edweek (0) = firstdayofmonth else edweek (0) = D. adddays (-6) end if edweek (1) = d Return edweek end if d = D. adddays (1) Next totalweeks = ed. length if Ed (ed. length-1) <= lastdayofmonth then totalweeks = totalweeks + 1 end if curweeks> = totalweeks then edweek (0) = ed (ed. length-1 ). adddays (1) edweek (1) = lastdayofmonth end if return edweek end Function
VB. NET obtains the range starting from Sunday according to the year, month, and week selected. The week is defined as from Sunday to Sunday ~ Saturday.