Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel Data Types Not Always Sticking
Message
From
27/01/2002 05:45:01
 
 
To
26/01/2002 22:45:33
Larry Nobs
Nobs Computer Services, Inc.
Saint Peters, Missouri, United States
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00611189
Message ID:
00611221
Views:
24
I am having trouble getting Excel to reliably keep data type settings....



The problem is not with Excel, but with your code.
From VFP Help:
TYPE( ) Function
Evaluates an expression and returns the data type of its contents.

...

Parameters
cExpression
Specifies the expression to be evaluated, which can be a variable, field, memo field, or any other expression. The expression must be passed as a character string; place quotation marks around the names of memory variables, fields, and so on. If you do not place quotation marks around the expression, the TYPE( ) function evaluates the contents of the string. If the contents cannot be evaluated as a valid FoxPro expression, TYPE() returns "U" (undefined expression).



So, I think your code should read:
oExcel=createobject('Excel.Application')
oexcel.visible = .t.
oexcel.Workbooks.add
test1 = oexcel.cells(10,10)
? type('test1') && RETURNED O which is what I expected
oexcel.cells(10,10).numberformat = "@"
oexcel.cells(10,10).value='test1'	
* ^^^ Note that having this value you may reference to the memory variable Test1 which you change from cell object, to cell contents
? type('oexcel.cells(10,10).value') 
* ^^^ Returns type of the contents of the Excel cell, and not the type of the variable with name contained in the Excel cell

test1 = oexcel.cells(10,10).value && From here Test1 contains the value of the cell
? type('test1') &&RETURNED C

? iif(type('test1')='C','CHARACTER','SOMETHING ELSE') &&RETURNED CHARACTER

? type('test1')
? type('oexcel.cells(10,10).value')
Hope this helps
Zlatin Zlatev,
MCSD (VS6)

Make solutions, not programs!

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform