Hi everyone!
I am entering only numbers with decimal points/values in a TEXTBOX on the VB form. I need to get only the decimal values.
How can I? Please help me as I tried in this way (for 2 Decimal places) - VB6
-
Dim x As Double
-
Dim dc As Integer, dcStr As String
-
-
x = Val(Text1.Text)
-
dc = InStr(x, ".")
-
If dc > 0 Then
-
dcStr = Left(Mid(Text1.Text, dc + 1) & "00", 2)
-
End If
-
ThnQ all !
6 16616
Hi everyone!
I am entering only numbers with decimal points/values in a TEXTBOX on the VB form. I need to get only the decimal values.
How can I? Please help me as I tried in this way (for 2 Decimal places)
:
:
ThnQ all !
Also can I restrict to enter only 2 decimal places?
I tried this code in TEXT_CHANGE() -
Dim x As Double
-
Dim dc As Integer, dcStr As String
-
-
x = Val(Text1.Text)
-
dc = InStr(x, ".")
-
If dc > 0 Then
-
dcStr = Left(Mid(Text1.Text, dc + 1) & "00", 2)
-
End If
-
s = s & dcStr
-
If Len(s) > 2 Then
-
MsgBox dcStr & "- More Decimals"
-
s = ""
-
End If
-
But I am getting problem when entering more than 2 decimals or if I backspace the digits.
Please Help me.
ThanQ!
Also can I restrict to enter only 2 decimal places?
I tried this code in TEXT_CHANGE()
But I am getting problem when entering more than 2 decimals or if I backspace the digits.
Please Help me.
ThanQ!
you can use doubles and singles instead of strings for this very problem - dim dou1 as double
-
dim sin1 as single
-
dou1=abs(text1.text)
-
sin1=dou1 - int(dou1)
Depending on the version, you might or might not have ABS, if you dont, just create it - public function abs( a as double) as double
-
if a < 0 then a = a * -1
-
abs = a
-
end function
If you want SIN1 as an integer, well, there are many ways: - while int(sin1) <> sin1
-
sin1=sin1*10
-
wend
or instead of doing that, to restrict it to N decimals just;
HTH
you can use doubles and singles instead of strings for this very problem
:
:
THANK YOU VERY VERY MUCH!
But how to restrict i could not get it!
ThanQ Once Again!
Hi Khadgar!
I changed the code as -
Dim dou1 As Double
-
Dim sin1 As Single
-
Dim n As Integer
-
dou1 = Abs(Text1.Text)
-
sin1 = dou1 - Int(dou1)
-
-
' While Int(sin1) <> sin1
-
' sin1 = sin1 * 10
-
'Wend
-
-
n = 2
-
sin1 = Round(sin1, n) * 10 ^ n
-
-
Text2.Text = sin1
-
ThaQ for an idea!
Hi Khadgar!
I changed the code as
...
ThaQ for an idea!
yeap, that's right, the first method is to keep all decimals, the second to restrict them, you shouldnt use both, or you'll get all the decimals plus N zeros.
yeap, that's right, the first method is to keep all decimals, the second to restrict them, you shouldnt use both, or you'll get all the decimals plus N zeros.
Yeah!
I did the same. Thank You!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Batista, Facundo |
last post by:
Here I send it.
Suggestions and all kinds of recomendations are more than welcomed.
If it all goes ok, it'll be a PEP when I finish writing/modifying the code.
Thank you.
.. Facundo
|
by: Peter Blatt |
last post by:
Does 5 represent the total numer of digits (including the fractional portion) or only the number of places
BEFORE the decimal point? Moreover does the number include the decimal point?
Are there...
|
by: Artek |
last post by:
Hello,
after installing .net 1.1, ASP.NET works fine, but there is a problems with
extra zeros added to the numbers at the end.
In Sql 2000 SP3a there is for example a table with one column ...
|
by: Amaryllis |
last post by:
Hi again,
I'm new to the world of communicating between VB.NET and AS/400, so
I've been posting a lot of questions lately since no one else in the
company has done anything like this before. ...
|
by: Kay Schluehr |
last post by:
I wonder why this expression works:
>>> decimal.Decimal("5.5")**1024
Decimal("1.353299876254915295189966576E+758")
but this one causes an error
5.5**1024
Traceback (most recent call...
|
by: Pieter |
last post by:
Hi,
I'm having some troubles with my numeric-types in my VB.NET 2005
application, together with a SQL Server 2000.
- I first used Single in my application, and Decimal in my database. But a...
|
by: =?Utf-8?B?UmljaA==?= |
last post by:
Is there a way to determine if a numeric value contains a decimal? how to do
this?
If IsNumeric(txt1.Text) then ... so now I know that txt1.Text is a numeric
value. How can I tell if it is a...
|
by: iDaz |
last post by:
hi everyone!
i've searched many sites including this one for the answer to me question, but i'm still in a bit of trouble. this is my current code...
Private Sub unitPriceKeyPress(ByVal sender...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I convert a Number into a String with
exactly 2 decimal places?...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |