View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default strange behaviour - no feedback!

In the same module, run this as a test. Make the immediate window is
visible.

Sub aa()
For counter = 0 To pi_maximum
Debug.Print counter
Next
End Sub

see if the loop is executed

the problem you are dealing with is either a logic error or a failure on
your part to understand variable scope. It isn't something VBA/Excel would
consider an error - because people might intentionally design their code so
the loop is never executed under certain conditions. By using an variable as
one of the loop conditions, you are taking responsibility for determining if
the loop will run or not. So if you want a warning, you will have to
include that in the logic of your code.

--
Regards,
Tom Ogilvy

-




wrote in message
oups.com...
Hi,
I`ve done some rather basic programming in excel and in general I find
vba a useful tool. However, from time to time I run into some problems
that are very annoying because the program is unable to report on what
line of code causes problems. Today, I tried to run a macro that enters
a loop like

for counter = 0 to pi_maxnum

but the code never entered the loop and the program just stopped and
I`m right back in manual control over excel. The solution was to
hardcode the loop like

for counter = 0 to 10

and everything ran fine.

The pi_maxnum was defined as public in another module, I also tried
defining it as public in the module with the sub containing the loop,
to no effect.

I`m no vba expert, someone here can probably point out the problem, but
when the system never even to reports on why nothing happens .. it
should be a law against it. In this case I would excpect a message on
something wrong with the definition of pi_maxnum.

Anyway, if someone cares to share some thoughts on this I`d be glad.