GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Microsoft  >  Visual Basic
Go To First  |  Previous Question  |  Next Question 
 Visual Basic  |  Question 450 of 453    Print  
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



  
Total Answers and Comments: 7 Last Update: June 18, 2008     Asked by: sriram_tvs 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 11, 2008 07:03:59   #1  
amolsarwade Member Since: February 2008   Contribution: 1    

RE: Displaying leading/trailing zero in text box

You can do so with textbox LostFocus e.g.
Private Sub Text1_LostFocus()
    Text1.Text = Format(Text1.Text, "0.00")
End Sub


 
Is this answer useful? Yes | No
February 11, 2008 11:37:09   #2  
Lavanyaaru Member Since: January 2008   Contribution: 13    

RE: Displaying leading/trailing zero in text box
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"
}

 
Is this answer useful? Yes | No
February 11, 2008 11:38:56   #3  
Lavanyaaru Member Since: January 2008   Contribution: 13    

RE: Displaying leading/trailing zero in text box
sorry dont use Format("#.##") contd.....use the following

Text1.Text = Format(Text1.Text, "0.00")

 
Is this answer useful? Yes | No
February 11, 2008 23:49:17   #4  
sriram_tvs Member Since: June 2007   Contribution: 7    

RE: Displaying leading/trailing zero in text box
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.
 

 
Is this answer useful? Yes | No
February 14, 2008 16:54:02   #5  
GSoni Member Since: November 2007   Contribution: 3    

RE: Displaying leading/trailing zero in text box
Define Normal Function in the form with the parameter Textbox while validate call this function with the parameter TexBboxName.

 
Is this answer useful? Yes | No
May 05, 2008 03:19:26   #6  
abhaykantnirala Member Since: May 2008   Contribution: 1    

RE: Displaying leading/trailing zero in text box

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


 
Is this answer useful? Yes | No
June 18, 2008 07:18:32   #7  
madhu3768 Member Since: June 2008   Contribution: 2    

RE: Displaying leading/trailing zero in text box
Write the below code in the lost focus event

text1,text = format(val(text1.text), "0.00")

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape