vb.net error message query?!

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2007
Posts: 57
Reputation: Run.[it] is an unknown quantity at this point 
Solved Threads: 1
Run.[it]'s Avatar
Run.[it] Run.[it] is offline Offline
Junior Poster in Training

vb.net error message query?!

 
0
  #1
Oct 15th, 2007
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

  1. Dim Index As Integer = 0
  2. Dim EmployeeRec(9) As EmployeeType
  3.  
  4. Private Sub add_bta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add_bta.Click
  5.  
  6. If Val(employeeid_txt.Text) > 10 Or Val(employeeid_txt.Text) < 1 Then
  7. MessageBox.Show("Employee Id Outwith Range 1 to 10 ", "Please re-enter", MessageBoxButtons.OK)
  8. Else
  9. EmployeeRec(Index).Employeeid = employeeid_txt.Text
  10. End If
  11.  
  12. EmployeeRec(Index).Status = "Active"
  13.  
  14. If Len(firstname_txt.Text) > 15 Or Len(firstname_txt.Text) = 0 Then
  15. MessageBox.Show("Firstname Outwith Range 1 to 15 ", "Please re-enter", MessageBoxButtons.OK)
  16. Else
  17. EmployeeRec(Index).Firstname = firstname_txt.Text
  18. End If
  19. If Len(surname_txt.Text) > 15 Or Len(surname_txt.Text) = 0 Then
  20. MessageBox.Show("Surname Outwith Range 1 to 15 ", "Please re-enter", MessageBoxButtons.OK)
  21. Else
  22. EmployeeRec(Index).Surname = surname_txt.Text
  23. End If
  24. If Val(Age_txt.Text) > 100 Or Val(Age_txt.Text) < 16 Then
  25. MessageBox.Show("Age Outwith Range 16 to 100 ", "Please re-enter", MessageBoxButtons.OK)
  26. Else
  27. EmployeeRec(Index).Details.Age = Age_txt.Text
  28. End If
  29. If Len(gender_txt.Text) > 6 Or Len(gender_txt.Text) < 4 Then
  30. MessageBox.Show("Gender must be Male or Female ", "Please re-enter", MessageBoxButtons.OK)
  31. Else
  32. EmployeeRec(Index).Details.Gender = gender_txt.Text
  33. End If
  34. If Len(position_txt.Text) > 15 Or Len(position_txt.Text) = 0 Then
  35. MessageBox.Show("Position Outwith Range 1 to 15 ", "Please re-enter", MessageBoxButtons.OK)
  36. Else
  37. EmployeeRec(Index).Position = position_txt.Text
  38. End If
  39.  
  40. Index = Index + 1
  41.  
  42. End Sub
Last edited by Run.[it]; Oct 15th, 2007 at 8:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: vb.net error message query?!

 
0
  #2
Oct 16th, 2007
use boolean varaible to indicate if the user enter correct value for each input like this
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 If

then if all inputs for user are correct , store that entry to your array

  1. if correct_EmployeeID and correct_firstname and correct_surname and correct_gender and correct_position then
  2. EmployeeRec(Index).Employeeid = employeeid_txt.Text
  3. etc ..etc
  4. End if
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

  1. If Val(employeeid_txt.Text) > 10 Or Val(employeeid_txt.Text) < 1 Then
  2. lable_error_id.text="Employee Id Outwith Range 1 to 10 , Please re-enter" Else
  3. correct_EmployeeID=true
  4. End If
Last edited by manal; Oct 16th, 2007 at 12:06 am.
"give only what u willing to receive "
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 57
Reputation: Run.[it] is an unknown quantity at this point 
Solved Threads: 1
Run.[it]'s Avatar
Run.[it] Run.[it] is offline Offline
Junior Poster in Training

Re: vb.net error message query?!

 
0
  #3
Oct 16th, 2007
Thanks Manal, thats helped a lot. Also your suggestion on better and more specific validation is insightful.

Cheers.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC