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:

01-Jan-09 Thursday, 02-Jan-09 Friday, 03-Jan-09 Saturday, 04-Jan-09 Sunday, 05-Jan-09 Monday, 06-Jan-09 Tuesday, 07-Jan-09 Wednesday, 08-Jan-09 Thursday, 09-Jan-09 Friday, 10-Jan-09 Saturday, 11-Jan-09 Sunday, 12-Jan-09 Monday, 13-Jan-09 Tuesday, 14-Jan-09 Wednesday, 15-Jan-09 Thursday, 16-Jan-09 Friday, 17-Jan-09 Saturday, 18-Jan-09 Sunday, 19-Jan-09 Monday, 20-Jan-09 Tuesday, 21-Jan-09 Wednesday, 22-Jan-09 Thursday, 23-Jan-09 Friday, 24-Jan-09 Saturday, 25-Jan-09 Sunday, 26-Jan-09 Monday, 27-Jan-09 Tuesday, 28-Jan-09 Wednesday, 29-Jan-09 Thursday, 30-Jan-09 Friday, 31-Jan-09 Saturday.

LevelText of 31 unique level (control) will display those dates. All the date must be valid. I’m requesting all of my seniors, plz plz help me.

Dani AI

Generated

A compact, reliable plan: take the selected month (as a numeric value) and year, compute how many days that month has, then loop from day 1 to that last day and produce a formatted string for each date together with its weekday name. The suggestions from and to use weekday functions are correct, and the DateSerial-based loop approach shown by (and echoed by ) is a proven way to do it.

Practical clarifications and fixes not yet emphasized in the thread:

  • Make the month-to-number mapping explicit. Do not rely on an alphabetically sorted combobox. Either populate the box in calendar order and use ListIndex+1, or store the month number in ItemData for each entry so the selection always yields the correct numeric month.
  • Convert the year text to an integer before passing it to date routines and use Option Explicit with properly typed variables (Date/Integer) to avoid subtle type errors.
  • Get the last day robustly by asking for the “zero-th” day of the next month (this automatically handles 28/29/30/31 and leap years).

UI and formatting tips:

  • Display is simpler with a ListBox, ListView, or grid rather than 31 separate static labels. If 31 controls are required, use a control array so captions can be set in a loop and unused controls hidden.
  • Use an explicit format mask when turning a Date into text so output does not vary with system locale. Choose full or abbreviated weekday names via the weekday-name routine and control the week-start value if needed.

Common pitfalls and quick checks:

  • Ensure ComboBox.Sorted = False when relying on position, check for an empty selection (ListIndex = -1), and test February on leap and non-leap years. Temporarily output the computed first and last dates before the loop to confirm the date range is correct.

Recommended Answers

All 8 Replies

1. select the month.
2. findout all the dates.
3. findout the days by passing the dates ---use WEEKDAYNAME function for the purpose.

Yes, Debasisdas is correct.
Refer

WeekDayName ()
WeekDay ()
&
Other Date Functions
to achieve this.

WeekDayName ( WeekDay ( Date ) ) returns today date in String

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.

Dear Salvaganapathy,

Please help me in details. Can you help me with some sample coding. Please....

Hi,

Try This Code:

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

Regards
Veena

Hi,

Try This Code:

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

Regards
Veena

Hi Sweetheart How r u ?

Hello veena,

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

Thanks veena.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.