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
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