View Full Version : Code help
av8tordude
05-10-2009, 06:08 PM
Can someone tell me why my code will not let me type 1.0, 2.0, 3.0, etc, but it will allow me to type 1.1, 2.1, 3.1, etc? If possible offer a solution to my delima. Thanks in advance.
Private Sub txtTOTAL_Change()
Dim v As String, tVal As Single
If Len(Me.txtTOTAL) Then
v = Replace(Me.txtTOTAL, ".", "")
tVal = Val(v) / 10
Me.txtTOTAL = tVal
End If
End Sub
If you start with 1.0, Replace returns the string "10". Then tVal returns the Single 1, as you divided 10 by 10.
If you start with 1.2, Replace returns the string "12". Then tVal return 1.2, as you divided 12 by 10.
Does that help?
Mark
av8tordude
05-10-2009, 08:35 PM
Thanks for the explaination GTO. The problem I'm having is it will not allow me to enter 1.0. It allows me to enter 1, but i will not allow me to enter 0.
mdmackillop
05-11-2009, 12:25 AM
Try
Private Sub txtTotal_AfterUpdate()
Bob Phillips
05-11-2009, 01:08 AM
Private Sub txtTOTAL_Change()
Dim v As String, tVal As Single
Dim ReEntry As Boolean
If Not ReEntry Then
ReEntry = True
With Me.txtTOTAL
If Len(.Text) Then
v = Replace(.Text, ".", "")
tVal = Val(v) / 10
.Text = tVal
End If
End With
ReEntry = False
End If
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.