PDA

View Full Version : Number format to dispaly on a label from text box



sujittalukde
06-23-2008, 11:20 PM
I am using the following code to display the number format on a label named Label5 whenever number is entered to a Textbox named Textbox3


Private Sub TextBox3_Change()
'TextBox3.Text = Format(TextBox3.Value, "[>=10000000]#\,##\,##\,##0;[>=100000]##\,##\,##0;##,##0")
Select Case TextBox3.Text
Case Is >= 1E+15
Label5.Caption = Format(TextBox3.Text, "##"",""00"",""00"",""00"",""00"",""00"",""00"",""000.00")
Case Is >= 10000000000000#
Label5.Caption = Format(TextBox3.Text, "##"",""00"",""00"",""00"",""00"",""00"",""000.00")
Case Is >= 100000000000#
Label5.Caption = Format(TextBox3.Text, "##"",""00"",""00"",""00"",""00"",""00"",""000.00")
Case Is >= 1000000000
Label5.Caption = Format(TextBox3.Text, "##"",""00"",""00"",""00"",""000.00")
Case Is >= 10000000
Label5.Caption = Format(TextBox3.Text, "##"",""00"",""00"",""000.00")
Case Is >= 100000
Label5.Caption = Format(TextBox3.Text, "##"",""00"",""000.00")
Case Else
Label5.Caption = Format(TextBox3.Text, "##,###.00")
End Select
End Sub


Now the problem is:
Suppose I want to write a number 12000 and the label should display 12,000 on textbox change event.

But when I press 1 it is going to case else, but next time when I press 2, the code enters into [Case Is >= 10000000000000#] and thus shows number format as ,00,00,00,00,00,012.00 whereas I want to display the same as 12 only on the label5 caption.

Why the code is entering to this case [Case Is >= 10000000000000#] instead of entering into Case else as 12 fits for that case.

JimmyTheHand
06-23-2008, 11:28 PM
You are comparing texts to numbers.
Try this:

Select Case Val(TextBox3.Text)

HTH

Jimmy

Bob Phillips
06-24-2008, 12:04 AM
Private Sub TextBox3_Change()
Label5.Caption = Application.Text(TextBox3.Text, _
"[>=10000000]##\,##\,##\,##0.00;[>=100000]##\,##\,##0.00;##,##0.00"
End Sub

sujittalukde
06-24-2008, 12:05 AM
Thanks Jimmy, its working. Now if I want to change the number format in the desired mode, as the user types the digits, instead of diaplaying on th label then whats the change I have to make ie if I wnat to write 12,000 then as and when the figures are typed number format will change as per Cases covered. In this code If I change Label5.caption to Textbox3.text then the cursor stops at 1.00 and cannot proceed to write 12000.