0

In the VBA immediate window, I can simply type the following at any time:

?Len("Four")

Press enter and get the result:

4

If I try to do that in Visual Studio Express (VB.NET), I get the following result:

The name 'Len' does not exist in the current context

I assume it has to do with VBA being a "scripting" language and VB.Net requiring compilation. I'm just looking for a simple way to evaluate expressions using functions from the built-in libraries.

mwolfe02
  • 23,787
  • 9
  • 91
  • 161

2 Answers2

1

I just created a new console app and tested both

?"Four".Length

and

?Len("Four")

both of which result in 4, after my project has run.

Do you have a project that will run? The immediate window needs to be evaluated in the context of a running project. If so,

Have you imported Microsoft.VisualBasic in your project properties "References" tab? If I remove that I get,

'Len' is not declared. It may be inaccesible due to its protection level.

But, the Length propery of System.String still works because I'm still importing System.

Jodrell
  • 34,946
  • 5
  • 87
  • 124
  • "Do you have a project that will run? The immediate window needs to be evaluated in the context of a running project." This seems to be the key bit of info I was missing. Creating a new console app seems to be the simplest solution if all I want to do is evaluate some expressions in the immediate window. Thanks for the insight! – mwolfe02 Feb 12 '13 at 17:02
1

Make sure you are currently stepping through your code.

Nick DeVore
  • 9,748
  • 3
  • 39
  • 41
  • This is not a requirement in VBA. Is this a requirement in VB.Net/Visual Studio? – mwolfe02 Feb 12 '13 at 16:58
  • This is it. Apparently the VS vhost has to actually be in the running state first. – RBarryYoung Feb 12 '13 at 17:01
  • It appears that Visual Studio will attempt to enter a running state automatically in some scenarios. Using @Jodrell's example of creating a new console application, I can then evaluate expressions in the immediate window without explicitly stepping through the code. VS will run the application even if the code consists of only the stock `Module Module1 Sub Main() End Sub End Module` – mwolfe02 Feb 12 '13 at 17:07