Immediate window - Compile error

  • Thread starter Thread starter Hari Prasadh
  • Start date Start date
H

Hari Prasadh

Hi,

Im in the middle of executing code. I have put a break point just after the
code has Read through the values in an Array called - arrwords.

I wanted to check whether the reading of array has been done properly, so
opened up the immediate window (Ctrl + G)
and wrote the following as it is (Stole from Chip's site)

? For N= LBound(arrWords) To UBound(arrWords): Debug.Print arrWords(N) :
Next N

I get a -- compile error : expected expression


But if i read through the array element by element then I dont get any
error.

? arrwords(4)
microsoft
? arrwords(3)
basic
? arrwords(2)
visual
? arrwords(1)
objects
? arrwords(0)
net

What am I doing wrong in the method of combining several lines of code in to
one single line of code.

Thanks a lot,
Hari
India
 
Debugging that way from the Immediate window can be terribly painful.

From the View menu choose Locals Window then expand arrwords.

Another way is to go View | Watch Window
Then from the Debug menu, Add Watch
The expression would be arrwords
 
More easily, if you open the watch window, select arrwords in the code,
click and drag it into the watch window. As Rob says, you can click the +
sign then and see all the values.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Hari,

Have to say I disagree with Rob, I think the immediate window is great for
debuggingh. But you have to use it correctly as with all things, and you
have a Debug.Print statemen t in there, so the print command (?) is not
needed,. You are trying to run some code, not check what a variable or a
statement returns.

Just do

For N= LBound(arrWords) To UBound(arrWords): Debug.Print arrWords(N) :
Next N

make sure N is defined in your code, as this construct is invalid
unfortunately

Dim N :For N= LBound(arrWords) To UBound(arrWords): Debug.Print arrWords(N)
: Next N

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Hi Bob,

Thnx for your post. Now am able to get the results.
you have a Debug.Print statement in there, so the print command (?) is not
needed
Initially I thought that -- ? -- and -- Debug.Print -- are synonymous. To
check the same, I tried the following :-

1) ? for i= LBound(arrWords) To UBound(arrWords): arrWords(i) :Next i
I again got a compile error : expected expression

2) for i= LBound(arrWords) To UBound(arrWords): Debug.Print
arrWords(i) :Next i
No error and correct results.

So for some time I was at my wit's end. Then I read very closely your
statement regarding -- You are trying to run some code, not check what a
variable or a statement returns.-- and
things became clearer.

Thanks a lot,
Hari
India
 

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

Back
Top