using Float input in textbox

Posted on 1999-08-02
Medium Priority
Last Modified: 2012-05-05
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?
Question by:jntj405
  • 2
  • 2
LVL 18

Accepted Solution

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




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
   StrtoFloat = a + c
End Function

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

and it DOES work.

 The decimal point type should be given in regional settings.


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

Author Comment

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

Also thanks to setiawan

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question