0

I'm having problem regarding a text box max length.

If i set it manually from the properties tab (i set it to 10), output would like

"10000000.0"

What i want is that it would be "1000000000.00". So i tried using this code:

Private Sub txtrate_LostFocus()

If txtrate.Text = vbNullString Then txtrate.Text = FormatNumber(0, 2)
txtrate.Text = FormatNumber(txtrate.Text, 2)

End Sub

But still doesn't work. Any idea?

3
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by AndreRet
0

Your textbox will not show the decimal values because the first 10 values is already used. You need to determine that if there is a decimal value, increase the max length to 13 to allow the "." and the two decimal characters "00".

If MyNumber > 10 Then
txtRate.MaxLength = 13
End If

Edited by AndreRet: n/a

0

Why not go for the Masked Edit Control instead of a regular textbox.

That control allows you to set a predefined format, and also allows for validation on entry, instead of after entry.

0

Still don't work sir.

Design and Run time, but didn't work. It always counts the period as an element or text.

I've tried removing all my codes but its just plain numbers without decimal places.

It should limit the first 5 numbers as its max length then at lost focus, it will automatically adds the ".00" value to the text.


Like 10000 turns to 10,000.00.

0

I replaced my original code (with yours) with this one:

Private Sub txtrate_LostFocus()

txtrate.Text = FormatNumber(txtrate.Text, 2)

End Sub
0

Change your code to -

Private Sub txtrate_LostFocus()

Dim strLen As String
strLen = FormatNumber(txtrate.Text, 2)

If Len(strLen) > 10 Then txtrate.MaxLength = Len(strLen)
txtrate.Text = strLen
End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.