Need to display a running collection of status messages

R

Randy K

Novice VBA question.

I’ve written a VBA program in ESRI's ArcMap software that takes and
imports a serices of coverages into a Spatial Database Engine.
Currently I use a series of msgbox commands to track execution of the
code. But what I’d like to do is display in a window a running
collection of all the text that is currently being displayed using
msgbox. I tried creating a form with a textbox but it will only
display text set before I show the form.

How should I be approaching this problem?

Public Sub TestResults()
'This does not work but illustrates conceptually what I want to do
frmResults.Show
frmResults.txtResults.Text = "Line 1"
frmResults.txtResults.Text = "Line 2"
End Sub



Thanks,
Randy K
(e-mail address removed)
 
P

Peter Hewett

Hi Randy K

This is fairly routine. But you may need to restructure the code a little. Here's code
pulled out of something I wrote last night for a client!:

<--------------Code in your module----------------->
Private mfrmS As frmStatus ' Declared outside the sub

Public Sub StartWork
' Display status Form, the status Form calls back to
' UpdateTemplates to do the actual work
Set mfrmS = New frmStatus
Load mfrmS
With mfrmS
.Folder = strFolder
.LogFile = mlogFile.File
.Show
End With

' Tidy up the Status form now that we're done with it
Unload mfrmS
Set mfrmS = Nothing
End Sub

Public Sub DoSomeWork()
Static lngCount As Long

' Do something

' Log it to the status form
lngCount = lngCount + 1
mfrmS.AddInfo = "Status line: " & lngCount
End Sub

I'm assuming you'll display the text in a ListBox as it may be easier to identify each
line. So you add the following code to your Form, this assumes that you have a ListBox
control named "lstStatusInfo":

Public Property Let AddInfo(ByVal AddInfo As String)
With lstStatusInfo
.AddItem AddInfo

' Force last item added to be visible
.TopIndex = .ListCount - 1
End With

' Force changes to be shown
Me.Repaint
End Property

You start by calling "StartWork" to load and display the Status form. The Status form
then calls the procedure "DoSomeWork", which does whatever it is you are doing. While
DoSomeWork executes it updates the Status Form using it's AddInfo property:
mfrmS.AddInfo = "Status line: " & lngCount

HTH + Cheers - Peter


(e-mail address removed) (Randy K), said:
 
P

Peter Hewett

Hi Randy K

I forgot to add - You can always use a log file, it's a lot easier.

HTH + Cheers - Peter
 

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

Top