View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default Excel 2002 - Iterations - Find the iteration sequence number

Um...

I don't think you can read the status bar during calculation from within
VBA.

An alternative and horribly kludgy approach to give you an idea of what
iteration you are on:

add this to a general module:

Public Function IterationCounter() As Long
IterationCounter = Application.Caller.Value + 1
End Function

'add this to the code for the sheet you are trying to monitor
Private Sub Worksheet_Calculate()
Cells(1, 1).ClearContents
Cells(1, 1).Formula = "=IterationCounter()"
End Sub

If there is no circular calculation in the sheet, create one.

Press calculate and watch the counter go up in the top left cell!

Robin Hammond
www.enhanceddatasystems.com


"Umfriend" wrote in message
m...
Gocush,

Thx for this, but I think it does not suffice. Your solution only
works when *I* have control of the statusbar, i.e., when I set the
value for it (But if I do that, then I would know what it is normally
;) ).

The show my problem I expanded your solution somewhat:
Sub tst1()
Dim SB As String
Dim i As Integer
Application.DisplayStatusBar = True

Debug.Print "Setting the Statusbar myself:"
Application.StatusBar = "hello"
SB = Application.StatusBar
Debug.Print SB & Application.StatusBar

Debug.Print "Having Excel Control the Statusbar"
Application.StatusBar = False
SB = Application.StatusBar
Debug.Print SB & Application.StatusBar
End Sub

This yields:
Setting the Statusbar myself:
hellohello
Having Excel Control the Statusbar
FALSEFALSE

What I want is to be able to read the actual text in the statusbar
(which with me is "Ready Calculate" but could be "Ready" and during
my UDF will be "Iter: [Iteration sequence number"]

So, either I would like to be able to read the actual text of the
statusbar _or_ have a way to find the actual Iteration Sequence
Number, which is really what I am currently looking for (reading the
statusbar is just a way I thought to try to get it)

Umf

gocush /delete wrote in message
...
Try this to get Statusbar value into a variable then do whatever with the
variable

Dim SB As String

Application.DisplayStatusBar = True
Application.StatusBar = "hello"
SB = Application.StatusBar
MsgBox SB

"Umfriend" wrote:

[SNIP]

QUESTION

Now I can print.debug everthing I want except for one thing: The
iteration sequence number it is currently working on. When it
iterates, the statusbar will show "Iter: ##", and I want to print that
number with the other debug values each time the UDF is called.

Is there a way to do this? I would be satisfied if I could "read" the
text in the statusbar and print that to the Immediate window, but I
have not found a way to do it.

[Geesh, that's a lot of text for a simple query, sry]