ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range vs IRange What's the difference? (https://www.excelbanter.com/excel-programming/323094-range-vs-irange-whats-difference.html)

Fredrik Wahlgren

Range vs IRange What's the difference?
 
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;

}



gocush[_29_]

Range vs IRange What's the difference?
 
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

"Fredrik Wahlgren" wrote:

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;

}




Fredrik Wahlgren

Range vs IRange What's the difference?
 
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



"gocush" /delete wrote in message
...
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

"Fredrik Wahlgren" wrote:

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;

}






gocush[_29_]

Range vs IRange What's the difference?
 
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.

"Fredrik Wahlgren" wrote:

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



"gocush" /delete wrote in message
...
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

"Fredrik Wahlgren" wrote:

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;

}







NickHK

Range vs IRange What's the difference?
 
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

"Fredrik Wahlgren" wrote in message
...
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



"gocush" /delete wrote in message
...
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

"Fredrik Wahlgren" wrote:

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;

}









All times are GMT +1. The time now is 05:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com