Connecting Tech Pros Worldwide Forums | Help | Site Map

Simple question - data format

Needs Regular Fix
 
Join Date: Sep 2007
Location: Canada
Posts: 274
#1: Jul 14 '09
When a user hit enter key to go to UnitCost field, price is selected to let user change default price it if he want.IF he press enter he moves to next field without changing it.
Problem is, if price is highlighted e.g 0.010 and user tries to enter .10 it doed not accept the decimal in the beginning. However 0.10 is accepted. The only case a decimal is allowed to enter as first position, is when user clears the existing entry.

I want to allow decimal at first position without clearing.
Please help it is urgent.

Here is my code

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtUnitCost_GotFocus()
  2.     txtUnitCost.SelStart = 0
  3.     txtUnitCost.SelLength = Len(txtUnitCost)
  4. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtUnitCost_KeyPress(KeyAscii As Integer)
  2.  
  3. 'Validation check
  4. ' Allows only numeric enteries in the code field discard other characters
  5.  
  6.     Select Case KeyAscii
  7.  
  8.         Case Asc(0) To Asc(9)
  9.         Case Str("8")
  10.         Case 46
  11.             Dim position1 As Integer
  12.             position1 = InStr(txtUnitCost.Text, ".")
  13.             If position1 <> 0 And KeyAscii = 46 Then
  14.             KeyAscii = 0
  15.             position1 = 0
  16.             End If
  17.        Case Else
  18.             KeyAscii = 0
  19.        End Select
  20.  
  21. End Sub
Thanks

Needs Regular Fix
 
Join Date: Sep 2007
Location: Canada
Posts: 274
#2: Jul 15 '09

re: Simple question - data format


IT is Vb6 question. Isn't it right spot to post this question. I am wonderinf if it is not possible to over right highlighted text with "." decimal?
smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#3: Jul 16 '09

re: Simple question - data format


Dear creative

replace following line :

Expand|Select|Wrap|Line Numbers
  1. 'If position1 <> 0 And KeyAscii = 46 Then
  2.  
with

Expand|Select|Wrap|Line Numbers
  1. If txtUnitCost.SelLength = Len(txtUnitCost) And KeyAscii = 46 Then
  2. ElseIf position1 <> 0 And KeyAscii = 46 Then
  3.  
Reply


Similar Visual Basic 4 / 5 / 6 bytes