I wanted to show an error message if the data (can be words or letters) entered but I don't have any idea on how:
-specify the types of characters used (whether numbers or letters)
-to limit the number of characters used
-and then go back to the form (where the error occur)
Additional info:
field name which need to have those message: ID(only numbers) and name(only letters)
Showing error message (database-vb.net)
Page 1 of 19 Replies - 1215 Views - Last Post: 07 September 2010 - 04:25 PM
Replies To: Showing error message (database-vb.net)
#3
Re: Showing error message (database-vb.net)
Posted 05 August 2010 - 05:54 AM
Thanks, I'm still experimenting it
#4
Re: Showing error message (database-vb.net)
Posted 05 August 2010 - 06:13 AM
could you or someone explain this
If chkStr.IndexOf(eChar) > -1 OrElse eChar = vbBack Then
#5
Re: Showing error message (database-vb.net)
Posted 05 August 2010 - 06:59 AM
The chkStr is a string of characters to check against. -1 means it didn't find the character you are typing (didn't return an index) or if the keypress is the back space. The indexes will be 0 or above if a match is found.
So Basically, if an index of 0 or more is returned or the backspace key is pressed ...
So Basically, if an index of 0 or more is returned or the backspace key is pressed ...
This post has been edited by CharlieMay: 05 August 2010 - 07:00 AM
#6
Re: Showing error message (database-vb.net)
Posted 05 August 2010 - 03:28 PM
what about my question on how to limit the number of characters used?
#7
Re: Showing error message (database-vb.net)
Posted 05 August 2010 - 03:59 PM
Use the textboxes maxlength property
#8
Re: Showing error message (database-vb.net)
Posted 06 August 2010 - 01:51 AM
What are the sender and textbox in this source code actually?
ByVal eChar As Char) As Boolean
Dim chkstr As String = "$0123456789."
If chkstr.IndexOf(eChar) > -1 OrElse eChar = vbBack Then
If CType(sender, TextBox).Text.IndexOf(".") > -1 Then
If CType(sender, TextBox).TextLength - CType(sender, TextBox).Text.IndexOf(".") > 2 And eChar <> vbBack Then
Return True
End If
End If
If eChar = "$" Then
If CType(sender, TextBox).TextLength > 0 Then
Return True
Else
Return False
End If
End If
If eChar = "." Then
If CType(sender, TextBox).Text.IndexOf(eChar) > -1 Then
Return True
Else
Return False
End If
End If
Return False
Else
Return True
End If
End Function
#9
Re: Showing error message (database-vb.net)
Posted 07 September 2010 - 03:36 PM
Sender is the object that send the signal of hapened event. For example :
On above code, the sender is btnOK. You use : CType(sender, textbox) because you implement the method on a TextBox so you have to convert the type of sender (commonly declare as System.Object) to a TextBox.
Hope it's clear and helping you
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
On above code, the sender is btnOK. You use : CType(sender, textbox) because you implement the method on a TextBox so you have to convert the type of sender (commonly declare as System.Object) to a TextBox.
Hope it's clear and helping you
#10
Re: Showing error message (database-vb.net)
Posted 07 September 2010 - 04:25 PM
Why do cast the same argument multiple times?
What if the type of sender can not be cast to a Textbox?
So it is even better to us a trycast, then test for for nothing.
CType(sender, TextBox)
Dim tb As TextBox=CType(sender, TextBox)
What if the type of sender can not be cast to a Textbox?
So it is even better to us a trycast, then test for for nothing.
Dim tb As TextBox = TryCast(sender, TextBox)
If tb Is Nothing Then Throw New ArgumentNullException("Sender is null")
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|