Click here to Skip to main content
15,895,792 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
textbox1.text = 2021 (Now.Year)
Textbox2.text = .. month (select 1-12)


By using Textbox tool, I want to display all dates of the month selected from Textbox2.


Thank you for your support

What I have tried:

example;
If 9(september) is selected in textbox2,
Date,         day of week
2021/9/1,    wed
2021/9/2,    Thur
2021/9/3,    Fri
.
.
.
2021/9/30,   Thur
Posted
Updated 31-Aug-21 21:38pm
v2
Comments
Maciej Los 1-Sep-21 3:30am    
Where do you want to display all days of month?
Andre Thang 1-Sep-21 3:45am    
in Textboxes.
CHill60 1-Sep-21 3:32am    
You forgot to include the code that you have tried
Andre Thang 1-Sep-21 3:45am    
It is been only two months I started programming. Therefore, I have no idea how to try. Please help me.

Use the DateTime.DaysInMonth(Int32, Int32) Method (System) | Microsoft Docs[^] then just loop from day 1 of month x, year y to the number of days in that month.

Remember to validate the input - i.e. Year is an integer, month is an integer between 1 and 12 (or use a slider control instead of a text box)
 
Share this answer
 
Comments
Andre Thang 1-Sep-21 3:43am    
Thank you very much for your comment. Could you give me a sample code for my question?
CHill60 1-Sep-21 4:07am    
Sorry. This is obviously homework from your course, so giving you sample code would not really be helping you to learn. Between the two solutions you already have here you know how to find the number of days in a month - so you could use a For...Next Statement[^], Solution 2 shows an alternative method where you can work out the date of the last day of month (the first date in a month is pretty obvious), then just keep adding 1 day to the "current" date until you get to the end of the month ("while" you have not reached the end) see While...End While Statement[^]
You've said that you want these details in TextBoxes - you would need 31 text boxes and a way of referencing them. A better solution would be to have one textbox that can take multiple lines - see VB.Net - TextBox Control[^]
On all these links I have given you there is sample code. You just need to piece the ideas together
Take a look at below example:

VB
Dim yr As String = textbox1.text
Dim mt As String = textbox2.text

Dim startDate As DateTime = New Date(Int32.Parse(yr),  Int32.Parse(mt), 1)
Dim endDate As DateTime = startDate.AddMonths(1).AddDays(-1)
Do While startDate <= endDate
	ListBox1.Items.Add(startDate)
	startDate = startDate.AddDays(1)
Loop


Feel freee to improve it to your needs ;)
 
Share this answer
 
v2
Comments
Andre Thang 1-Sep-21 4:07am    
Thank you very much. All days in a month are displayed.
How to display day of week(Monday to Sunday) for each month?
CHill60 1-Sep-21 4:09am    
I know you have only been coding for 2 weeks but you must learn to do your own research!
vb.net day of week name - Google Search[^]
Maciej Los 1-Sep-21 4:25am    
:D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900