Home All Groups Group Topic Archive Search About

vb.net 2003 Formatting ... aghhhhhhhhhhhhhhhhh

Author
16 Oct 2006 1:33 PM
Peter Newman
i need help,  im at my wits end,  carnt for the life of me understand whats
wrong

I have written private sub to handle validating of text boxes

    Private Sub Handles_Validating(ByVal source As Object, ByVal e As
EventArgs) _
    Handles  textbox1.validated  ,  ???  .etc

     Dim tx As TextBox = DirectCast(source, TextBox)
      tx.Text = Format(Microsoft.VisualBasic.Right("000000" + tx.Text, 6),
"0#-##-##")

      Why oh why when entering in 123456 do i get 0#-##-## instead of
12-34-56 ???   HELP !!!!!!

Author
16 Oct 2006 2:22 PM
Phill W.
Peter Newman wrote:

>      Dim tx As TextBox = DirectCast(source, TextBox)
>       tx.Text = Format(Microsoft.VisualBasic.Right("000000" + tx.Text, 6),
> "0#-##-##")
>   
>       Why oh why when entering in 123456 do i get 0#-##-## instead of
> 12-34-56 ???   HELP !!!!!!

"0" and "#" only work when formatting /numbers/ - you're passing it a
/String/.   Without going all ".Net-y" on you, try this:

tx.Text = Format(Val(tx.Text), "0#-##-##")

HTH,
    Phill  W.