Range vs IRange What's the difference?

F

Fredrik Wahlgren

Hi

I found a C# example of an Excel add-in at
http://www.codeproject.com/dotnet/excelnetauto.asp. I made some changes to
this project and made a function that takes an Excel.Range as a parameter.

Intellisense showed that there is an interface called IRange as well as
Range. What's the difference? When would you want to use an IRange?

TIA,
Fredrik


Here's my added C# function.


public int GetRangeSize1(Excel.Range range)
{

return range.Columns.Count * range.Rows.Count;

}
 
G

gocush

IRange is neither an Excel or VBA object, method or property.
As far as I know the only way it could be used in the above is as a Variable
as in

Sub GetIRangeValue()
Dim IRange as Integer
Dim Rng as Range

Set Rng = Sheet1.Range("A1")
IRange = Rng.Value
Msgbox IRange
End Sub
 
F

Fredrik Wahlgren

No, you have dim'ed Irange as as an integer. If you use VB6 or VB.NET you
can do this

Dim r as Excel.Irange

C#

Excel.IRange r;

It compiles fine but I don't understand how I would use this variable.
IRange will also appear if you use the OLE/COM Object viewer and create an
idl file from excel.exe

/Fredrik
 
G

gocush

Sorry, I thought you were asking how IRange could be used in programing VBA.
In vba the first letter "i" or "I" is usually used to indicate that you
have dimmed your variable as an integer - as in my example. This is not
absolutely required but good programming practice.

As for programming in C# as you are doing, that is beyond the scope of this
forum and should be posted to an appropriate forum.
 
N

NickHK

Fredrik,
Recently I wrote a sets of classes that all Implement my "IBarCodeFormat"
interface.

This allows you to write something like:
Dim ThisBarCodeFormat as IBarCodeFormat

Set ThisBarCodeFormat =New EAN13
or
Set ThisBarCodeFormat =New EAN8
or
Set ThisBarCodeFormat =New Code39

as you can be sure that the class signatures will match the interface (by
definition)

So for you, I would guess the class "Range" Implements the "IRange"
interface. However, I'm not sure if that is any use to you, unless may be
you wanted to write your own "MyRange" class that had the same signature as
Excel's, but different functionality.

This is from a VB/VBA perspective on using Implements. C# or VB.Net may well
be different due to their appraoch to object, inheritance etc.

NickHk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top