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
5
Medium Priority
?
416 Views
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?
0
Comment
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
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

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

by:setiawan
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

by:deighton
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

by:setiawan
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

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

Thanks
Also thanks to setiawan
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

670 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