9 Replies - 1529 Views - Last Post: 07 September 2010 - 04:25 PM Rate Topic: -----

#1 Bluen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 02-August 10

Showing error message (database-vb.net)

Posted 05 August 2010 - 03:31 AM

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)
Is This A Good Question/Topic? 0
  • +

Replies To: Showing error message (database-vb.net)

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

Re: Showing error message (database-vb.net)

Posted 05 August 2010 - 04:22 AM

I have a snippet that should help with what you are wanting to do. Check it out and see if it helps you.
Was This Post Helpful? 1
  • +
  • -

#3 Bluen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 02-August 10

Re: Showing error message (database-vb.net)

Posted 05 August 2010 - 05:54 AM

Thanks, I'm still experimenting it
Was This Post Helpful? 0
  • +
  • -

#4 Bluen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 02-August 10

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

Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

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 ...

This post has been edited by CharlieMay: 05 August 2010 - 07:00 AM

Was This Post Helpful? 1
  • +
  • -

#6 Bluen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 02-August 10

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?
Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

Re: Showing error message (database-vb.net)

Posted 05 August 2010 - 03:59 PM

Use the textboxes maxlength property
Was This Post Helpful? 1
  • +
  • -

#8 Bluen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 02-August 10

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? :eh:
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

Was This Post Helpful? 0
  • +
  • -

#9 emresutisna  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 80
  • Joined: 14-May 09

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 :
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 :smile2:
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Showing error message (database-vb.net)

Posted 07 September 2010 - 04:25 PM

Why do cast the same argument multiple times?
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")


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1