validating text boxes
-
Hi I am kinda new to vb.net and I am having problems with code that works when it suits it. The code is meant to check if data has been entered into the text boxes. For some unknown reason it works on one form but the same code copied and pasted does not work on a different form. this the code. 'This checks the textboxes to see if the data entered is correct Dim ctrlx As Control For Each ctrlx In Controls If TypeOf ctrlx Is TextBox Then If ctrlx.Text = "" Then ctrlx.Focus() MessageBox.Show("Please enter the required data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If End If Next I hope u will be able to help me, twsted f8
-
Hi I am kinda new to vb.net and I am having problems with code that works when it suits it. The code is meant to check if data has been entered into the text boxes. For some unknown reason it works on one form but the same code copied and pasted does not work on a different form. this the code. 'This checks the textboxes to see if the data entered is correct Dim ctrlx As Control For Each ctrlx In Controls If TypeOf ctrlx Is TextBox Then If ctrlx.Text = "" Then ctrlx.Focus() MessageBox.Show("Please enter the required data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If End If Next I hope u will be able to help me, twsted f8
Don't post the same message twice.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Hi I am kinda new to vb.net and I am having problems with code that works when it suits it. The code is meant to check if data has been entered into the text boxes. For some unknown reason it works on one form but the same code copied and pasted does not work on a different form. this the code. 'This checks the textboxes to see if the data entered is correct Dim ctrlx As Control For Each ctrlx In Controls If TypeOf ctrlx Is TextBox Then If ctrlx.Text = "" Then ctrlx.Focus() MessageBox.Show("Please enter the required data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If End If Next I hope u will be able to help me, twsted f8
You cannot compare the type of control with TextBox Class. The control has to be compared with the type of TextBox. Possibly the the code snippet will resolve your issue For Each ctrl As Control In Me.Controls If ctrl.GetType() Is GetType(TextBox) Then If ctrl.Text="" Then MessageBox.Show("Message",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) ctrl.Focus() End IF End If Next Santosh Metal