1
Vote

Resize doesn't resize range

description

In VBA when doing resize on a range it will resize the range. But when I do it with NetOffice it returns the index of the range. E.g.,
 
rng=Range("A2:C14")
rng2=rng.Resize(rng.Rows.Count, 1)
 
Now rng2 should be:
 
"A2:A14"
 
But instead it is:
 
"A14"
 
Likewise, if I do this:
 
rng2=rng.Resize(Type.Missing, 1)
 
Should return:
 
"A2:A14"
 
But instead returns:
 
"A2"

comments

SebastianDotNet wrote Jul 19, 2012 at 9:18 PM

hey jon,

i do a test in c# netoffice 1.5.1

Excel.Range rng = workSheet.Range("A2:C14");
Excel.Range rng2 = rng.Resize(rng.Rows.Count, 1);
string address = rng2.Address(Type.Missing, Type.Missing);

// address is "$A$2:$A$14;

which netoffice version you use?

Jon49 wrote Jul 24, 2012 at 12:03 AM

I was using 1.4, I switched to 1.5 and I am still getting the same bug, I'm using VB.NET on an XP office 2003. Let me know if you need more information.

Here's the code I am using:

Dim rCompare = rng.Resize(rng.Rows.Count, 1).Offset(0, iCompareColumn - rng.Column)

When I check the value what rng.Resize does I get this:

?rng.Address(True,True)
"$A$2:$E$14"
?rng.Resize(rng.Rows.count,1).Address(True,True)
"$A$14"
?rng.Resize(Type.Missing,1).Address(True,True)
"$A$2"

SebastianDotNet wrote Jul 24, 2012 at 6:21 AM

rng is workSheet.Range("A2:C14") ??
please replace iCompareColumn to a constant just for me.

Jon49 wrote Jul 24, 2012 at 10:17 PM

iCompareColumn is 1 and rng.Column is 1. But that doesn't really reflect the core problem which is:

?rng.Address(True,True)
"$A$2:$E$14"
?rng.Resize(rng.Rows.count,1).Address(True,True)
"$A$14"
?rng.Resize(Type.Missing,1).Address(True,True)
"$A$2"

For some reason this is not working correctly, even when I use a newer version of NetOffice. Let me know if you want me to send you my project.

BTW, I sent you a link to a website that should make doing the LINQ in C# coding much easier. It was done by Jon Skeet, someone who is really knowledgeable on the subject. He did 42 different implementations.

http://msmvps.com/blogs/jon_skeet/archive/2011/02/23/reimplementing-linq-to-objects-part-45-conclusion-and-list-of-posts.aspx

Hope that is helpful for your LINQ project.

SebastianDotNet wrote Aug 2, 2012 at 9:06 PM

hello jon,

sorry for the delay, please checkout: http://netoffice.codeplex.com/wikipage?title=Download%20Page

the example works fine for me.
modify the example and show me whats wrong. please send the modified example to public.sebastian@web.de

thanks!!!
Sebastian

Jon49 wrote Aug 2, 2012 at 9:56 PM

OK, I ran your example and I was still getting the wrong answer, as seen below:

range2.Address is $A$14
Press any key...

I didn't change any of the code, just opened it and ran it.

I'm using an XP with Office 2003 Professional. Since I didn't change anything I won't send you the code back. Let me know if you still want me to send it to you.

SebastianDotNet wrote Aug 3, 2012 at 4:42 PM

hey jon,

patrick o beirne helps me to understand the real problem. its a syntax issue.
Resize is a property with parameters that returns a range. VB developers has one syntactical issue here( C# evelopers not) you have to call get_Resize(1,1) the given parameter in your code are affected to the returned range, look at the intellisense(rowIndex, columnIndex) the overloads without get_ exists but VB can't see them. i hope i find a better solution for the next release.

Sebastian