Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Retrieve value using vb6 from an excel workbook - precision question

Hi All
I have a Vb6 app from which I am retreiving a value in a cell in a
worksheet in a workbook.

The code goes something like this:

SomeLabel.caption = MyCells(rownum,colnum).value

Looking directly at the cell in the workbook, I see a value of 3.

However when I debug.print or msgbox MyCells(rownum,colnum).value from
the vb6 app, I find that the value is actually more like 2.9999889889
or something similar.

Whether I format the cell in the workbook as a number to 0 decimal
places, or as General, makes no difference. I conclude from this that
the vb6 code is actuall retrieving the excel *stored* value rather than
the excel *presented* value. Is this correct? How do I retrieve the
value "3" rather than the entire floating point value? Or is the only
way to coerce the data type in the vb6 app using a ceiling like
function or declaring a variable as type integer and assigning it?

Any help appreciated.

Regards
Andrew

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Retrieve value using vb6 from an excel workbook - precision questi

You are 100% correct!

Something like
Dim v As Variant
v = Cells(1, 1).Value

will pick up what you call the *stored* value. The *displayed* value is
just smoke & mirrors. For example, you can format 1 to appear as a 2.

Your solutions are equally correct.
--
Gary's Student


"CodeMonkey" wrote:

Hi All
I have a Vb6 app from which I am retreiving a value in a cell in a
worksheet in a workbook.

The code goes something like this:

SomeLabel.caption = MyCells(rownum,colnum).value

Looking directly at the cell in the workbook, I see a value of 3.

However when I debug.print or msgbox MyCells(rownum,colnum).value from
the vb6 app, I find that the value is actually more like 2.9999889889
or something similar.

Whether I format the cell in the workbook as a number to 0 decimal
places, or as General, makes no difference. I conclude from this that
the vb6 code is actuall retrieving the excel *stored* value rather than
the excel *presented* value. Is this correct? How do I retrieve the
value "3" rather than the entire floating point value? Or is the only
way to coerce the data type in the vb6 app using a ceiling like
function or declaring a variable as type integer and assigning it?

Any help appreciated.

Regards
Andrew


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Retrieve value using vb6 from an excel workbook - precision question

Andrew,

I think that your conclusions are correct.

Rounding and ceiling is the obvious solution, but don't forget that there
are worksheetfunctions to call upon, such as Round, Roundup, etc.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"CodeMonkey" wrote in message
oups.com...
Hi All
I have a Vb6 app from which I am retreiving a value in a cell in a
worksheet in a workbook.

The code goes something like this:

SomeLabel.caption = MyCells(rownum,colnum).value

Looking directly at the cell in the workbook, I see a value of 3.

However when I debug.print or msgbox MyCells(rownum,colnum).value from
the vb6 app, I find that the value is actually more like 2.9999889889
or something similar.

Whether I format the cell in the workbook as a number to 0 decimal
places, or as General, makes no difference. I conclude from this that
the vb6 code is actuall retrieving the excel *stored* value rather than
the excel *presented* value. Is this correct? How do I retrieve the
value "3" rather than the entire floating point value? Or is the only
way to coerce the data type in the vb6 app using a ceiling like
function or declaring a variable as type integer and assigning it?

Any help appreciated.

Regards
Andrew



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Retrieve value using vb6 from an excel workbook - precision question

Hi Andrew,

These floating point problems also occur in VBA. If you're not concerned
with long decimals maybe coerce to a Single

Sub test()
Dim v
Dim dbl As Double
Dim sng As Single
Dim i As Long

For i = 1 To 10
Cells(i, 1).Formula = "=1/10"
Next

[a11].Formula = "=Sum(a1:a10)" ' should =1, but in XL only approximately

v = [a11].Value
dbl = [a11].Value
sng = [a11].Value

Debug.Print v = 1, v - 1
Debug.Print dbl = 1, dbl - 1
Debug.Print sng = 1, sng - 1

End Sub




"CodeMonkey" wrote in message
oups.com...
Hi All
I have a Vb6 app from which I am retreiving a value in a cell in a
worksheet in a workbook.

The code goes something like this:

SomeLabel.caption = MyCells(rownum,colnum).value

Looking directly at the cell in the workbook, I see a value of 3.

However when I debug.print or msgbox MyCells(rownum,colnum).value from
the vb6 app, I find that the value is actually more like 2.9999889889
or something similar.

Whether I format the cell in the workbook as a number to 0 decimal
places, or as General, makes no difference. I conclude from this that
the vb6 code is actuall retrieving the excel *stored* value rather than
the excel *presented* value. Is this correct? How do I retrieve the
value "3" rather than the entire floating point value? Or is the only
way to coerce the data type in the vb6 app using a ceiling like
function or declaring a variable as type integer and assigning it?

Any help appreciated.

Regards
Andrew



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Retrieve value using vb6 from an excel workbook - precision question

Many thanks to all for replying so promptly.

Regards
Andrew

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RETRIEVE DATA FROM ANOTHER WORKBOOK BY CHECKING ON WORKBOOK DATE Joe Excel Worksheet Functions 13 May 27th 08 01:52 AM
Retrieve Excel Workbook Brunopeecees Excel Worksheet Functions 0 November 23rd 06 11:19 AM
Precision displayed does not match precision in cell James Wilkerson Excel Discussion (Misc queries) 10 June 15th 05 02:40 PM
programatically retrieve selected rows from excel workbook talktobatchu Excel Programming 0 June 1st 05 10:15 PM
precision question D[_5_] Excel Programming 2 April 15th 05 09:37 PM


All times are GMT +1. The time now is 07:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"