Solved

Problem to compare double with lenght over 15 digits in visual basic 6

Posted on 2007-04-09
8
813 Views
Last Modified: 2008-01-09
I face a problem to compare double with lenght over 15 digits in visual basic 6.
For example:
Dim a  as double, b as double
a = "100000000000000000"
b = "100000000000000001"
when compare a = b .. this will return True. Why true ?
when a = a + 1.. it shows 1E + 17.. how to make it show 100000000000000001 ? Pls help. Thanks.
0
Comment
Question by:alankwan
[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
  • 3
  • 2
8 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 18880808
The only possible I know is to declare the variable variant.
Dim a, b
0
 
LVL 15

Accepted Solution

by:
JackOfPH earned 125 total points
ID: 18880851
0
 
LVL 11

Assisted Solution

by:TreyH
TreyH earned 125 total points
ID: 18881976
Working with that many significant digits (In VB6) would require a 3rd party library. I've used one called xlPrecision. There's a free edition you can download to try it out. It's mainly designed for Excel but I've used it in VB with no problem.

http://precisioncalc.com/xlprecision.html
http://precisioncalc.com/UseInVBA.html

Example Code for comparing your two numbers.

Dim oXLP As xlPrecision.cls_xlPrecision
Set oXLP = New xlPrecision.cls_xlPrecision
If oXLP.xlpISEQUAL("100000000000000000", "100000000000000001") Then
    MsgBox "Numbers are equal"
Else
    MsgBox "Numbers are not equal"
End If
Set oXLP = Nothing
0
 
LVL 11

Expert Comment

by:TreyH
ID: 19131607
Your call Dan, anything fine by me...
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 19155165
Yeah, its your call...
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

730 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