1

I'm trying to have a Textfield lose it's leading zeroes when the user leaves the field. I made the following "Leave" event but it's not working. It works for the first half however to set it back to 1 if it's blank or if a user entered 0.

I tried following the advice on this answer, but it didn't work:

Removing leading zeroes from a string

Private Sub FirstTableTxt_Leave(sender As System.Object, e As System.EventArgs) Handles FirstTableTxt.Leave
    If FirstTableTxt.Text = "" Or FirstTableTxt.Text = "0" Then
        FirstTableTxt.Text = "1"
    End If

    FirstTableTxt.Text = Convert.ToString(CInt(FirstTableTxt.Text))
End Sub

EDIT: I see where I went wrong with this. I was thinking that Convert.Toxxxx returns it to the same variable.

Community
  • 1
  • 1
Paul Williams
  • 1,554
  • 7
  • 40
  • 75

1 Answers1

12
FirstTableTxt.Text = FirstTableTxt.Text.TrimStart("0"c)
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794