Reputation: 90
Something strange, This form is opened from another from but I want the form to close and return to the initial form if user input are missing. This is not happening, WHY ?
Try
Dim din As Int32 = (Form1.ComboBox1.SelectedValue)
Dim dt As String = Form1.Label1.Text
Dim dt2 As String = Form1.Label2.Text
If din = Nothing Or dt = Nothing Or dt2 = Nothing Then
MessageBox.Show("Please Select a Staff and Date Range", "Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Hide()
Form1.Show()
Else
' MsgBox(din & "/" & dt & "/" & dt2)
DataGridView1.DataSource = getTable(din, DateTime.Parse(dt), DateTime.Parse(dt2))
DataGridView1.AutoResizeColumns()
Me.Text = "Selected Staff: " & CStr(Form1.ComboBox1.Text)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Upvotes: 0
Views: 372
Reputation: 90
Thanks guys, I finally figured out that I am better off checking the user selections in the original form rather than checking for null values in the called up form.
I appreciate all your input. Thanks.
Upvotes: 0
Reputation: 101142
You use the Text
property of Labels
Dim din As Int32 = (Form1.ComboBox1.SelectedValue)
Dim dt As String = Form1.Label1.Text
Dim dt2 As String = Form1.Label2.Text
If din = Nothing Or dt = Nothing Or dt2 = Nothing Then
but they will never be Nothing
. If you try to set Nothing
to a Text
property of a Control
, it will use an empty string instead. I think that is your main problem.
Also, you convert the SelectedValue
property to Integer
and check it for Nothing
. Note that this will be true
if the SelectedValue
is 0
, since it's the default value of Integer
.
You should use a debugger and step through your code to be able to solve such problems.
Upvotes: 2