Displaying leading/trailing zero in text box

Hi,
i have many text boxes to input numeric values in the form. The problem is when my text box lost its focus , if any numeric value entered in text box without any dismal place will automatically display 2 dismal zero. else if no values entered in the text box it should display 0.00 value in it .
ex : if i enter a value in the text box : 25 when it lost focus the values should 25.00
if doesn't enter any value in text box, when it lost focus the value should be 0.00

Questions by sriram_tvs   answers by sriram_tvs

Showing Answers 1 - 24 of 24 Answers

The above answer is partially correct. You have to add a conditional statement, otherwise everytime u leave the text box, Lost focus event would fire and it would set it to zero.

If u r using VB 6.0 , u could always use the Validate Event instead of Lost focus event

If Val(Text1.text)>0 then
{

Text1.text = Format("#.##")
}

else

{
Text1.text = "0.00"
}

  Was this answer useful?  Yes

thank u ,
i have 20 to 30 text boxes in each form  and having 10 to 15 froms in my project , bit difficult to write the text bix validate code for each text box . so is it possible by using  user defined function.
 

  Was this answer useful?  Yes

GSoni

  • Feb 14th, 2008
 

Define Normal Function in the form with the parameter Textbox while validate call this function with the parameter TexBboxName.

  Was this answer useful?  Yes

It is very simple. Do coding at LostFocus event as

Private Sub Text1_LostFocus()
If Text1.Text<>"" Then
    Text1.Text= 0. & Text1.Text

Eelse

    Text1.Text=0.00

End If
End Sub

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions