| | |
vb.net error message query?!
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
Currently my program fires out error messages when the user enters information outwith the boundaries. However for every valid entry these will be stored in the array and the entry outwith the boundaries will be listed as blank which I dont want. Id like the program to only store an entry in the array if all the criteria for the boundaries are met. Could anyone advise me how to do this?
Thanks
Thanks
VB.NET Syntax (Toggle Plain Text)
Dim Index As Integer = 0 Dim EmployeeRec(9) As EmployeeType Private Sub add_bta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add_bta.Click If Val(employeeid_txt.Text) > 10 Or Val(employeeid_txt.Text) < 1 Then MessageBox.Show("Employee Id Outwith Range 1 to 10 ", "Please re-enter", MessageBoxButtons.OK) Else EmployeeRec(Index).Employeeid = employeeid_txt.Text End If EmployeeRec(Index).Status = "Active" If Len(firstname_txt.Text) > 15 Or Len(firstname_txt.Text) = 0 Then MessageBox.Show("Firstname Outwith Range 1 to 15 ", "Please re-enter", MessageBoxButtons.OK) Else EmployeeRec(Index).Firstname = firstname_txt.Text End If If Len(surname_txt.Text) > 15 Or Len(surname_txt.Text) = 0 Then MessageBox.Show("Surname Outwith Range 1 to 15 ", "Please re-enter", MessageBoxButtons.OK) Else EmployeeRec(Index).Surname = surname_txt.Text End If If Val(Age_txt.Text) > 100 Or Val(Age_txt.Text) < 16 Then MessageBox.Show("Age Outwith Range 16 to 100 ", "Please re-enter", MessageBoxButtons.OK) Else EmployeeRec(Index).Details.Age = Age_txt.Text End If If Len(gender_txt.Text) > 6 Or Len(gender_txt.Text) < 4 Then MessageBox.Show("Gender must be Male or Female ", "Please re-enter", MessageBoxButtons.OK) Else EmployeeRec(Index).Details.Gender = gender_txt.Text End If If Len(position_txt.Text) > 15 Or Len(position_txt.Text) = 0 Then MessageBox.Show("Position Outwith Range 1 to 15 ", "Please re-enter", MessageBoxButtons.OK) Else EmployeeRec(Index).Position = position_txt.Text End If Index = Index + 1 End Sub
Last edited by Run.[it]; Oct 15th, 2007 at 8:24 pm.
use boolean varaible to indicate if the user enter correct value for each input like this
then if all inputs for user are correct , store that entry to your array
other thing about your code , your validation based on test the length of the user's input
and that not correct , I can enter something like "abcd" and your program will accept it in the gender input , it is better to compare the user's input string with "male" or "female"
and much better to make user select the gender , and position (use radio button). about the error messages , what if user make more than one error ! many messages will show and that will be annoying , use labels to show the error messages
If Val(employeeid_txt.Text) > 10 Or Val(employeeid_txt.Text) < 1 Then
MessageBox.Show("Employee Id Outwith Range 1 to 10 ", "Please re-enter", MessageBoxButtons.OK)
Else
correct_EmployeeID=true
End Ifthen if all inputs for user are correct , store that entry to your array
VB.NET Syntax (Toggle Plain Text)
if correct_EmployeeID and correct_firstname and correct_surname and correct_gender and correct_position then EmployeeRec(Index).Employeeid = employeeid_txt.Text etc ..etc End if
and that not correct , I can enter something like "abcd" and your program will accept it in the gender input , it is better to compare the user's input string with "male" or "female"
and much better to make user select the gender , and position (use radio button). about the error messages , what if user make more than one error ! many messages will show and that will be annoying , use labels to show the error messages
VB.NET Syntax (Toggle Plain Text)
If Val(employeeid_txt.Text) > 10 Or Val(employeeid_txt.Text) < 1 Then lable_error_id.text="Employee Id Outwith Range 1 to 10 , Please re-enter" Else correct_EmployeeID=true End If
Last edited by manal; Oct 16th, 2007 at 12:06 am.
"give only what u willing to receive "
![]() |
Similar Threads
- Error Message: Cannot find server; page cannot be displayed (Viruses, Spyware and other Nasties)
- Server Error message when opening asp.net applicationm (ASP.NET)
- error message on MSN (Windows NT / 2000 / XP)
- Page Cannot be diplayed/DNS error message (Viruses, Spyware and other Nasties)
- Error message when downloading updates (Windows NT / 2000 / XP)
- spybot german error message (Viruses, Spyware and other Nasties)
- error message when connecting to internet (Windows NT / 2000 / XP)
- Reload page Error message when starting Windows XP (Viruses, Spyware and other Nasties)
- Help! C:\WINNT\system32\bridge.dll error message (Viruses, Spyware and other Nasties)
Other Threads in the VB.NET Forum
- Previous Thread: Need some help with my program
- Next Thread: how to create subdomain ?
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial server shutdown soap sorting survey table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





