Solved

# using Float input in textbox

Posted on 1999-08-02
Medium Priority
421 Views
I have a program that must fill in an amount in a db. There it is defined as float. Now when the user changes the data the decimal point is saved and displayed in the textbox. But when I use the value in the textbox for a function, the decimal point is lost. Can anyone help me?
0
Question by:jntj405
• 2
• 2

LVL 18

Accepted Solution

deighton earned 300 total points
ID: 1528907
pass the value of the text box using

val(text1.value)

or

cdbl(text1.value)
0

LVL 6

Expert Comment

ID: 1528908
You can't use CDbl(text1.text) -> won't return decimal point
val(text1.text) will work fine, If you put "." as separator
ie : 100.2
but it won't work if you use "," ie : 100,2

Try this
Private Function StrtoFloat(s As String) As Double
Dim i As Byte
Dim a As Double
Dim b As Byte
Dim c As Double
For i = 1 To Len(s)
If (Mid(s, i, 1) = ",") Or (Mid(s, i, 1) = ".") Then
a = CDbl(Left(s, i - 1))
b = Len(s) - i
c = CDbl(Right(s, b)) / (10 ^ b)
Exit For
End If
Next
StrtoFloat = a + c
End Function

0

LVL 18

Expert Comment

ID: 1528909
What do you mean cDbl won't work.  I've tested

Dim x As Double

x = CDbl(Text1.Text)
Debug.Print x
Stop

and it DOES work.

The decimal point type should be given in regional settings.

0

LVL 6

Expert Comment

ID: 1528910
I have tested too
sorry I don't know about that, would you tell me what regional setting should be set ?
BTW both CDbl or Val still won't return true value if  using "," as separator in the textbox
0

Author Comment

ID: 1528911
CDbl doesn't work. But Val does.

Thanks
Also thanks to setiawan
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.