I received an "InvalidOperationException was unhandled" Error
Here's what it states:
An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'
Here's a brief description on what I'm trying to do:
On form1 I have a button called btnChangeDate and label called lblDate
On form2 I have a calendar(MonthCalendar1) and a button called btnDate and a textbox called txtDateSelect which would be invisible.(It would be visible for test purposes only).
When form1 opens, it displays the current date in a certain format. If the user wants to select a different date, they would select btnChangeDate which opens form2. Once desired date is selected and the user clicks on button (btnDate) it is then displayed in txtDateSelect.
Here's the code.
Public Class Form1
Private Sub Label1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblDate.TextChanged
Dim a As Integer
Dim hour As Integer = DateTime.Now().Hour
Select Case hour
Case 0 To 6, 23
a = 1
Case 7 To 14
a = 2
a = 3
'Sets Date Code format
lblDate.Text = Date.Now.ToString("S" & "yyMMdd" & a)
Form2.txtDateSelect.Text = Me.lblDate.Text Part of problem is here
Private Sub btnChangeDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangeDate.Click
Code for form2 (It displays the calendar)
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Private Sub txtDateSelect_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDateSelect.TextChanged
Form1.lblDate.Text = Me.txtDateSelect.Text Here's where the other part problem is. This line of code and the other on form1 is why I'm getting that message
To summarize if the user wants to change the current date displayed then they would click on btnChangeDate. Once form2 opens they select date from calendar and press btnDate which then displays selected date in txtDateSelect as well as in lblDate.text located on form1.
Sorry about the long explanation. Hope it makes sense and Thanks for your help.