Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need text box to display three decimal places 1

Status
Not open for further replies.

DK47

Programmer
Jun 3, 2003
118
0
0
US
Hi All,
The application I am working on requires tracking investment shares with percentages extended to three digits.
IE (567.098 shares)

I know I could get this to work with mskbox but I have grown to detest those nasty little controls and besides the application has so many references to the existing text boxes it would take hours to find and change them.

The calculated share count will eventually be saved in a Jet 4 data base and I seem not to be having any trouble getting the 3 decimals to save there. At least not yet.
It appears that the database field will hold decimals even if the data format is set to Integer, is that true or should the field be set to Double?


Here is the VB6 code I am using to set the number of shares in the text with decimals. When focus is lost and the value is zero, the three decimal places show 0.000 but as soon as a positive value is calculated the zeros are dropped and the number is rounded to the nearest whole number.
As a little aside to this, I noticed a little thing about how vb rounds numbers. It seems that if the whole number is odd and the decimal is .5 the number rounds up and if the number is even the .5 rounds down!!!! ??????
Example 2.5 rounds to 2
1.5 rounds to 2

OK Here is my code.

Private Sub txtSharesBought_LostFocus()
If IsNumeric(txtSharesBought) = False Then
txtSharesBought = FormatNumber(0, 3)
MsgBox "A numeric value must be present in this box."
txtSharesBought.SetFocus
Exit Sub
Else
txtSharesBought = FormatNumber(txtSharesBought, 3)
End If
End Sub

Even if I input a number with three decimals, when the text loses focus vb rounds to a whole number with no decimal places.
Any suggestions will be greatly appreciated.
Dwight



 
I have tried to duplicate your problem and I cannot. Is there any code written on the get focus event for this text box? Or is there code somewhere else that hits this text box on some event that gets fires off in what you are checking?

I would recommend stepping through more than this event. I've put pretty much identical code into a form and it works just like what you want. No rounding to whole numbers.

Is the text box bound to your database? You can't put floating point numbers into integer fields. Your database is probably truncating the number to make it fit the column. The more I think about it- the more I bet that is your problem.

 
Dear SP,
I did what you suggested and found that on the form load event I had a calculation procedure that, early on in the programming, I had trouble with text boxes with variable not adding but concotinating. I used the Int(txtBox) function on it to force an addition.
Some how I must have decided, I don't remember doing it now, to prepare the shares texts the same way.

I have been racking my brain for a couple of hours. Your suggestion got me to the problem in minutes. Thank you.

Also I have reformatted my data base fields, where required, for Double.

The fields are all returning three decimal places now, in the database and the appication.
Thank you for giving me a push in the right direction,

Have a great night.
Dwight


LET'S GO PATS ( I'm a Tom Brady fan)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top