-
Aug 4th, 2013, 12:49 AM
#1
Thread Starter
Junior Member
-
Aug 4th, 2013, 12:53 AM
#2
Re: How to display all dates of a selected month in separate labels.
I think you'll have to clarify a bit. You have 10 'Labels' which look like ComboBoxes to me, what exactly do you want to display in the 'labels'?
-
Aug 4th, 2013, 01:09 AM
#3
Thread Starter
Junior Member
Re: How to display all dates of a selected month in separate labels.
Doogle,
There are labels and combo boxes below them.
When I select the month in the combo box at the top, I want the label's captions to fill in with the dates of the selected month.
And then, that will allow me to select a value for the particular date.
The labels are headings for those combo boxes in the frame and the value of those headings should be the dates of the month.
The month will be selected in the combo box which says "Select Month".
Thank you in advance.
-
Aug 4th, 2013, 01:14 AM
#4
Re: How to display all dates of a selected month in separate labels.
It must be too early in the morning for me, but all months have more than 27 days yet you have only 10 Labels.
Please could you give an example of what you'd expect in the 10 labels if I chose September as the Month?
-
Aug 4th, 2013, 01:19 AM
#5
Thread Starter
Junior Member
Re: How to display all dates of a selected month in separate labels.
Right now I am trying to get 10 dates in the label boxes.
I will add 21 labels and combo boxes more once I get it right for 10.
The form is still "Under Construction".
-
Aug 4th, 2013, 01:44 AM
#6
Re: How to display all dates of a selected month in separate labels.
You need to derive the number of days in the selected Month (and Year will be important to cater for February in Leap Years) and then set up a For /Next loop to populate the Captions.
Code:
Private Sub cmbMonth_Click()
Dim intI As Integer
Dim intDays As Integer
intDays = DaysInMonth(cmbMonth.Text)
If intDays <> -1 Then
For intI = 1 To intDays
label1(intI - 1).Caption = CStr(intI)
Next intI
Else
MsgBox "Invalid Month or year"
End If
End Sub
Private Function DaysInMonth(strMonth As String, Optional strYear As String = vbNullString) As Integer
If strYear = vbNullString Then strYear = Format(Now, "YYYY")
Select Case True
Case IsDate("31/" & strMonth & "/" & strYear)
DaysInMonth = 31
Case IsDate("30/" & strMonth & "/" & strYear)
DaysInMonth = 30
Case IsDate("29/" & strMonth & "/" & strYear)
DaysInMonth = 29
Case IsDate("28/" & strMonth & "/" & strYear)
DaysInMonth = 28
Case Else
DaysInMonth = -1
End Select
End Function
The above assumes that the Label for January is Label1(0), by default the Year is assumed to be the current year.
-
Aug 4th, 2013, 02:09 AM
#7
Thread Starter
Junior Member
Re: How to display all dates of a selected month in separate labels.
Thanks Doogle,
That works like a charm...
-
Aug 4th, 2013, 02:28 AM
#8
Re: How to display all dates of a selected month in separate labels.
If you have finished with the thread please mark it "Resolved".
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 4th, 2013, 02:36 AM
#9
Re: [RESOLVED] How to display all dates of a selected month in separate labels.
Another Example:
I used cmbMonths as combo's name. DateSerial creates a date given day + month + year, DateAdd adds or substracts days/months/years to any given Date.
Questions:
1) What about the year? Shouldn't the user be able to also select a year? (In this example i used current year).
2) What will you do with labels that won't be used? You could keep all labels invisible when you clear and make visible only those you'll use, like i did here with line Label1.Item(i - 1).Visible = True, but you could also just clear text on them if you use transparent labels, decide what's best for you.
Code:
Private Sub FillDays()
Dim i As Long, LngMonth As Long, LngLastDayInMonth As Long, DateFirstDayNextMonth As Date
LngMonth = cmbMonths.ListIndex + 1
'We create a new Date Variable that will be on the first day next month
DateFirstDayNextMonth = DateAdd("M", 1, DateSerial(Year(Date), LngMonth, 1))
'We substract one day from previous Date to get last day in this Month:
LngLastDayInMonth = Day(DateAdd("D", -1, DateFirstDayNextMonth))
'Fill labels with dates
For i = 1 To LngLastDayInMonth
Label1.Item(i - 1).Visible = True
Label1.Item(i - 1).Caption = FormatDateTime(DateSerial(Year(Date), LngMonth, i), vbShortDate)
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|