PDA

View Full Version : Solved: Textbox format



lhardee
05-09-2008, 04:46 PM
Hello,

Mike Erickson helped me out a bunch with the following code. I marked the question as solved, but found out that I can not enter zero values. I tried changing "S[1-9]*" to "S[0-9]*" but this did not fix the problem. Could someone show me where I'm going wrong ??

Thanks







Private Sub TextBox1_Change()
Static abort As Boolean
Dim sLStart As Long, sLLength As Long

If abort Then abort = False: Exit Sub
With Me.TextBox1
sLStart = .SelStart
sLLength = .selLength
abort = True
If .Text Like "S[1-9]*" Then
.Text = "S" & Int(Val(Mid(.Text, 2)))
Else
.Text = "S"
End If
.SelStart = Application.Max(sLStart, 1)
.selLength = sLLength
End With
End Sub




lhardee

tpoynton
05-09-2008, 06:30 PM
not sure what the original context/requirements were, but this seems to work...it at least allows zeros consistently. just add the Not to the if statement, and then comment out the next two lines, as below.

I'm pretty confident this will come at a cost to some other aspect of what you were trying to accomplish, though.




Private Sub TextBox1_Change()
Static abort As Boolean
Dim sLStart As Long, sLLength As Long

If abort Then abort = False: Exit Sub
With Me.TextBox1
sLStart = .SelStart
sLLength = .selLength
abort = True
If Not .Text Like "S[0-9]*" Then
'.Text = "S" & Int(Val(Mid(.Text, 2)))
'Else
.Text = "S"
End If
.SelStart = Application.Max(sLStart, 1)
.selLength = sLLength
End With
End Sub

lhardee
05-09-2008, 06:53 PM
tpoynton

Fantastic !!!! Works great. Thank you very much. I understand now how your change makes the difference.

Thank you very much for taking the time. I will mark this solved.....for real this time. :thumb

lhardee