move cursor to its position if non integer value is entered in a textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    move cursor to its position if non integer value is entered in a textbox

    Hi everyboyd, im trying to make a function which will keep the cursor to its position if non integer value is entered into a textbox. im using the following code:

    Code:
    Public Class Form1
        Private Sub txtNo_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNo.KeyUp
            NumericOnly(txtNo.Text)
        End Sub
        Public Function NumericOnly(ByVal sValue As String) As String
            Dim sAns As String
            Dim sChar As String
            Dim sNewString As String
            Dim lLen As Long
            Dim lCtr As Long
            Dim nc As Integer
    
            sAns = sValue
            lLen = Len(sValue)
            For lCtr = 1 To lLen
                sChar = Mid(sAns, lCtr, 1)
                If Asc(sChar) > 47 And Asc(sChar) < 58 Then
                    sNewString = sNewString & sChar
                End If
            Next
            NumericOnly = sNewString
            txtNo.Text = sNewString
            nc = txtNo.SelectionStart
        End Function
    End Class
    in the above code im getting the curose position in nc variable but i dont know how to move the cursor to dat position please tell me how i can do this.

    thanx
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    #2
    i solved it thanx for helping me.

    Comment

    Working...