-1

I am trying to convert simple vba "with statemnt" to C#. ProductRangeA and B are named ranges. Could someone to give a hint?

With ProductRangeA
   myRow= .Rows.Count: 
   myValue= .Value  
End With

With ProductRangeB
   myRow= .Columns.Count: 
   myValue= .Value  
End With
Jim
  • 2,760
  • 8
  • 42
  • 66
  • there's no equivalent in C#. You can achieve a similar syntax with some `Action` based code. – Federico Berasategui Jan 30 '14 at 18:04
  • @HighCore I can't think of how you would approximate it with `Action` -- can you post an example? – phoog Jan 30 '14 at 18:08
  • Hi I am looking at same functionality, meaning that the syntax could be differrent. thanks – Jim Jan 30 '14 at 18:11
  • Check this link, there are several similar methods: http://stackoverflow.com/questions/481725/with-block-equivalent-in-c – Hink Jan 30 '14 at 18:12

1 Answers1

1

As HighCore said, there's no C# equivalent to VB's With block. Here's the equivalent C# code:

myRow = ProductRangeA.Rows.Count;
myValue = ProductRangeA.Value;

myRow = ProductRangeB.Columns.Count;
myValue = ProductRangeB.Value;

Since you can't avoid typing ProductRangeA and ProductRangeB twice each, you can reduce typing by using shorter variable names. That can make the code more difficult to understand, of course.

phoog
  • 42,068
  • 6
  • 79
  • 117