Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# using Float input in textbox

Posted on 1999-08-02
Medium Priority
416 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
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 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.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
###### Suggested Courses
Course of the Month5 days, 2 hours left to enroll