0

Sorry for my stupid question, but I can´t understand just for it be so simple.

Excel 2010 stops running when I try the code below:

Sub Delay()

Dim j As Double
Dim i As Double
Dim k As Double

    For i = 1 To 1000000
        j = Sqr(i)
        k = 0
        Do While k < 1000000
            j = Sqr(k)
            k = k + 1
        Loop
    Next

End Sub

This sub does nothing, just spends time. So why excel is not responding?

VBA can´t be so weak. What am I losing?

Thanks.

Joe
  • 25,000
  • 3
  • 22
  • 44
Gera
  • 31
  • 1
  • 1
  • 7
  • 1
    You are asking it to calculate over a trillion square roots, even if it could do a billion per second it would take nearly 20 minutes – Joe Sep 08 '13 at 04:14
  • Thanks, Joe, I didn´t stop to calculate the time it could take. I tried for i <= 10,000 and k <= 10,000, what means one hundred milion of iteractions, and it spent nearly 4 seconds, but didn´t stop. I toke this sugestion (but with only one loop) from a microsoft page. – Gera Sep 08 '13 at 12:59

1 Answers1

0

What you're doing there is causing excel to go into a loop for 1,000,000 iterations. What you're trying to do is probably best answered by this post

Community
  • 1
  • 1
ermagana
  • 1,090
  • 6
  • 11