I’m very very new in VB6.0 in my project I need a function where I want to pass month name as variable value which will be selected from a combo box by user and the function will generate the full date from starting to end along with the weekday name.
Suppose user select the month “JANUARY” and year from different combo box. Under combo box click event that function will work and will generate the valid date from 1st January to 31th January along with the weekday name. like:
1. select the month.
2. findout all the dates.
3. findout the days by passing the dates ---use WEEKDAYNAME function for the purpose.
Dear debasis,
As i have mentioned i'm very new in VB and your profile says that you are much experienced. Can you give me some example or some sample coding which will meet the needful? Please bro, I need it.
Dim FromDate As Date
Dim ToDate As Date
Dim TempDate As Date
Combo1.clear
FromDate = DateSerial(Val(cmbYear.Text), (CmbMonth.ListIndex+1), 1)
ToDate = DateAdd("m", 1, FromDate)
ToDate = ToDate - 1
TempDate = FromDate
For TempDate = FromDate To ToDate
Combo1.AddItem (Format(TempDate, "dd-mm-yyyy") & " " _
& WeekdayName(Weekday(TempDate)))
Next
Populate Months in Combobox in the Ascending Order(Jan, Feb, Mar...), and keep Sorted of ComboMonth = False
Dim FromDate As Date
Dim ToDate As Date
Dim TempDate As Date
Combo1.clear
FromDate = DateSerial(Val(cmbYear.Text), (CmbMonth.ListIndex+1), 1)
ToDate = DateAdd("m", 1, FromDate)
ToDate = ToDate - 1
TempDate = FromDate
For TempDate = FromDate To ToDate
Combo1.AddItem (Format(TempDate, "dd-mm-yyyy") & " " _
& WeekdayName(Weekday(TempDate)))
Next
Populate Months in Combobox in the Ascending Order(Jan, Feb, Mar...), and keep Sorted of ComboMonth = False
Thank you very much for the support. I also found a way:
' given month number (1 through 12) and year, generate list of all days in month:
monthNum = 1 ' or wherever you get this from, e.g., from the combo box
yearNum = 2009
Dim firstOfMonth As Date, lastOfMonth As Date
firstOfMonth = DateSerial( yearNum, monthNum, 1 )
lastOfMonth = DateSerial( yearNum, monthNum+1, 0 )
For myDate = firstOfMonth To lastOfMonth
Dim oneDate As String
oneDate = Right("0" & Day(myDate),2) & "-" & MonthName(Month(myDate),True) _
& Right(CStr(Year(myDate)),2) & " " & WeekdayName(Weekday(myDate))
... do something with "oneDate" ...
Next