Serving the Quantitative Finance Community

 
User avatar
BillG
Topic Author
Posts: 0
Joined: September 30th, 2002, 5:54 am

What exactly is a Range in Exel?

September 30th, 2002, 8:44 am

I'm writtng a function in a dll. I would like to pass a Range from excel to my dll. I DON'T want to use automation because it's slow and a completely ridiculous concept! And I'm sure as hell not writting an xll, I would like to be done some time this year! I also want to minimize the amount VBA code because it's slow as hell(ah microsoft how bout making it compilable to quicken it up?)!My idea on this it to write a TYPE definition of a RANGE in VBA... wrap the range object up so to speak into a user defined type. Then I can pass that type to my dll, which will have it's own copy of the type defintion so it know what it's getting.That way I avoid automation and minimize the VBA code... which will give me speed, speed, and more speed. YEAH. Except I don't know what microsoft's type definiton of a Range is. Can anyone help me with this?(I'm only working with ranges that have numbers in them).TYPE somearbitrarynamestuff?stuff?more stuff?END TYPE
 
User avatar
rector
Posts: 0
Joined: July 14th, 2002, 3:00 am

What exactly is a Range in Exel?

September 30th, 2002, 4:28 pm

Hi, BillG,What you want to do makes good sense. However there is no reason to pass a real range object into a C++ code unless you really want acces the cells on the spreadsheet but not only process the data. To pass just an array of data from a range of cells define your C++ function so that it accepts variant type as an argument, sayvoid f(VARIANT * arg);and call it in your VBA code in the following wayCall f(Range("A1200").Value)Than the function will receive an array of values from the cells of the range with correct dimensions.Regards,Rector
 
User avatar
rector
Posts: 0
Joined: July 14th, 2002, 3:00 am

What exactly is a Range in Exel?

September 30th, 2002, 4:32 pm

Hi, BillG,What you want to do makes good sense. However there is no reason to pass a real range object into a C++ code unless you really want acces the cells on the spreadsheet but not only process the data. To pass just an array of data from a range of cells define your C++ function so that it accepts variant type as an argument, sayvoid f(VARIANT * arg);and call it in your VBA code in the following wayCall f(Range("A1:K200").Value)Than the function will receive an array of values from the cells of the range with correct dimensions.Regards,RectorP.S. In the previous post o few symbols in the code line were coverted into a smile by the forum. So, I post the whole message again.
 
User avatar
PinballWizard
Posts: 4
Joined: March 13th, 2002, 4:36 pm

What exactly is a Range in Exel?

October 1st, 2002, 12:19 am

BillGrector is right. If you're creating a non-COM dll, then it would be counter-productive to 'redefine' the RANGE type in your dll - else, you should stay in the COM world. Passing arrays of values is the way to go. There are many posts in this forum which explain how to go about passing arrays from VBA to C/C++ and vice-versa.PinballWizard
 
User avatar
BillG
Topic Author
Posts: 0
Joined: September 30th, 2002, 5:54 am

What exactly is a Range in Exel?

October 1st, 2002, 3:16 am

My whole point is to avoid automation(COM...COM+...ole...ActiveX...whatever you want to call it...microsoft changes it's name once a year for a reason I yet have determined ) It's all the same stuff... basically it's nothing but an interface.A varaint is nothing more than a wrapped SafeArray(automation)... so by definition it's using automation. Not only that, I have to use MFC and automation to access it, which is getting on the ridiculous side(plus all that code underneath is slowing my dll down a lot). All I want to do, is pass a selected range to my dll. However, I need to know how the selected range I pass looks in memory so I can access it in my dll. Hence, I need to put it's type definition in my dll so it know what the hell I've passed to it. Does anybody know what I'm talking about?
 
User avatar
audetto
Posts: 0
Joined: March 12th, 2002, 4:08 pm

What exactly is a Range in Exel?

October 2nd, 2002, 6:39 am

If you don't want to write an XLL you need to access a VARIANT (or you could do a very bad thing...: look in a similar thread in this forum... to know more about): teh VARIANT comes from Range(...).Valuebut you need only "SafeArrayGetDim", "SafeArrayGetUBound", and "SafeArrayGetElement" in the beginning of you code to produce a doubke ** pure-C variable and then you will use only standard C function. you don't even need MFC but only should you #include <windows.h>good luck
 
User avatar
rector
Posts: 0
Joined: July 14th, 2002, 3:00 am

What exactly is a Range in Exel?

October 2nd, 2002, 5:40 pm

BillG,Of course, there is a way to convert the content of a rectangular range of cells into an array of, say, doubles. You can do it directly in your VBA code. But you've got a 99% chance that your C++ program will do it faster. Because Excel will anyway covert VARIANT values from the cells of the range into doubles or whatever you want.Moreover, if you pass a Range object into your code, you'll have to use automation as well as COM for every access operation to this object, which will in turn be much slower than any of the methods to pass an array of data into your dll.Regards,Rector