fathimasulthan
Programmer
Hello,
I am Having a text box in which i should allow to enter only numerics and decimal points till the maximum length alowed for that text box. for that I have written the code as below,
NumericOnly : this function is alllowed to enter Only numeric values till the maxlength.(Maxlength includes '.')
NavigateCtl: This function is used to move the cursor to the Next control when the maxlength of character is attained.
'.' is also not allowed to enter in the text box. To enter the value 67.99, the User will enter as 6799 (wihtotu decimel point) after miving from that text box.. that value wilL be chaged to 67.99 for which i have writen code In validate evnt of the text box
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MY CODE GOES LIKE THIS..............
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub txtLumpSumAmt_KeyPress(KeyAscii As Integer)
NumericOnly txtLumpSumAmt, KeyAscii, txtLumpSumAmt.MaxLength - 1
NavigateCtl KeyAscii, txtLumpSumAmt, txtLumpSumAmt.MaxLength - 1, "INTEGER"
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This is to allow only numeric depending upon the max length
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function NumericOnly( _
strInput As String, _
intKeyAscii As Integer, _
intMaxLength As Integer, Optional objname As Object) _
As Integer
Select Case intKeyAscii
Case vbKeyBack, 8, 48 To 57
If intKeyAscii <> vbKeyBack Then
If InStr(strInput, "."
Then
If Len(strInput) >= intMaxLength Then
intKeyAscii = 0
End If
Else
If Len(strInput) > intMaxLength - 1 Then
intKeyAscii = 0
End If
End If
End If
Exit Function
Case Else
intKeyAscii = 0
End Select
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This is used to move to the net controL when the maxlength is entered.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub NavigateCtl(intKeyAscii As Integer, strContent As String, MaxLength As Integer, Optional Chartype As String)
If Chartype = "INTEGER" Then
Select Case intKeyAscii
Case 48 To 57
If InStr(strContent, "."
Then
If Len(strContent) >= MaxLength And Not intKeyAscii = vbKeyBack Then
SendKeys "{TAB}"
End If
Else
If Len(strContent) = MaxLength - 1 And Not intKeyAscii = vbKeyBack Then
SendKeys "{TAB}"
End If
End If
Case Else
If Len(strContent) >= MaxLength And Not intKeyAscii = vbKeyBack Then
SendKeys "{TAB}"
End If
End Select
end if
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
When the text box got foucus the text in the text box will be highlighted. When the Text box is highlighted if i press some value.. then the old value should be replaced.. Here comes my problem..
If the text box has characters < maxlength then i have No problem..
If the textbox has characters= maxlength then. and higlighted. if i press any value..it is not replaced as I have written numeric only till maxlength. So if it has maxlength of characters.. i have made keyascii=0 , So it is Not replace...
Hope u got My problem.. Hope I am very clear..
Can anybody give me solution by seing the code???
Thanks in advance
Fathima
I am Having a text box in which i should allow to enter only numerics and decimal points till the maximum length alowed for that text box. for that I have written the code as below,
NumericOnly : this function is alllowed to enter Only numeric values till the maxlength.(Maxlength includes '.')
NavigateCtl: This function is used to move the cursor to the Next control when the maxlength of character is attained.
'.' is also not allowed to enter in the text box. To enter the value 67.99, the User will enter as 6799 (wihtotu decimel point) after miving from that text box.. that value wilL be chaged to 67.99 for which i have writen code In validate evnt of the text box
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MY CODE GOES LIKE THIS..............
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub txtLumpSumAmt_KeyPress(KeyAscii As Integer)
NumericOnly txtLumpSumAmt, KeyAscii, txtLumpSumAmt.MaxLength - 1
NavigateCtl KeyAscii, txtLumpSumAmt, txtLumpSumAmt.MaxLength - 1, "INTEGER"
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This is to allow only numeric depending upon the max length
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function NumericOnly( _
strInput As String, _
intKeyAscii As Integer, _
intMaxLength As Integer, Optional objname As Object) _
As Integer
Select Case intKeyAscii
Case vbKeyBack, 8, 48 To 57
If intKeyAscii <> vbKeyBack Then
If InStr(strInput, "."
If Len(strInput) >= intMaxLength Then
intKeyAscii = 0
End If
Else
If Len(strInput) > intMaxLength - 1 Then
intKeyAscii = 0
End If
End If
End If
Exit Function
Case Else
intKeyAscii = 0
End Select
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This is used to move to the net controL when the maxlength is entered.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub NavigateCtl(intKeyAscii As Integer, strContent As String, MaxLength As Integer, Optional Chartype As String)
If Chartype = "INTEGER" Then
Select Case intKeyAscii
Case 48 To 57
If InStr(strContent, "."
If Len(strContent) >= MaxLength And Not intKeyAscii = vbKeyBack Then
SendKeys "{TAB}"
End If
Else
If Len(strContent) = MaxLength - 1 And Not intKeyAscii = vbKeyBack Then
SendKeys "{TAB}"
End If
End If
Case Else
If Len(strContent) >= MaxLength And Not intKeyAscii = vbKeyBack Then
SendKeys "{TAB}"
End If
End Select
end if
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
When the text box got foucus the text in the text box will be highlighted. When the Text box is highlighted if i press some value.. then the old value should be replaced.. Here comes my problem..
If the text box has characters < maxlength then i have No problem..
If the textbox has characters= maxlength then. and higlighted. if i press any value..it is not replaced as I have written numeric only till maxlength. So if it has maxlength of characters.. i have made keyascii=0 , So it is Not replace...
Hope u got My problem.. Hope I am very clear..
Can anybody give me solution by seing the code???
Thanks in advance
Fathima