MartinS
Active Member
- Joined
- Jun 17, 2003
- Messages
- 490
- Office Version
- 365
- Platform
- Windows
Hi
So I have been working on an application for some time, and we are getting close to having a fully working version. One minor issue I have is with the way the user sees what is happening. The logic required is that the user doesn't have to sit there and not know where abouts the code is - he may want to run it for many records and multiple scenarios so it can take anything from a minute or so up to 10 minutes, maybe more. This way, the user gets to see the events as they run using text that makes sense as each procedure is called. So here is how I've set this up:
I've added a userform (225 high by 337.5 wide) with three label controls, lblStatus1 (18 high by 322 wide), lblStatus2 (150 high by 322 wide) and lblStatus3 (12 high by 322 wide). The first and third are standard labels which sit above and below the second (top for 1 is 6, 2 is 30 and 3 is 186).
The second label (lblStatus2) has a white background, and a single border, with an opaque backstyle.
Here is the userform's activate event:
The form also has a public property:
When a ribbon button is clicked, it runs a procedure to load and initialise the userform:
The code behind this is as follows:
As you can see, this loads the form and sets the text for the first label, adds the title and stores the procedure name into the property.
Then, before each subsequent event that is run within the overall procedure (RunMyEvents), another call is made, e.g.:
Here is the procedure code:
This code writes the text to the specific label (usually 2, label 3 is redundant for the moment) and if blank, it simply adds the text, but if there is already text, i.e. several procedures have already been run, then it appends it to the end.
The issue I have is that we are running many procedures as it loops through several iterations, and once the text in lblStatus2 gets longer than 15 lines, you can't see the progress. I tried switching to a ListBox, but that just added a scrollbar, when what I'd like is the top one to be removed each time a new one is added so you only ever see, say in this example, 15 lines.
I can't figure out how to add the lines, and then remove the top one each time! Or is there an easier/smarter way to do this?
Any help or advice gratefully received.
Many thanks
Martin
So I have been working on an application for some time, and we are getting close to having a fully working version. One minor issue I have is with the way the user sees what is happening. The logic required is that the user doesn't have to sit there and not know where abouts the code is - he may want to run it for many records and multiple scenarios so it can take anything from a minute or so up to 10 minutes, maybe more. This way, the user gets to see the events as they run using text that makes sense as each procedure is called. So here is how I've set this up:
I've added a userform (225 high by 337.5 wide) with three label controls, lblStatus1 (18 high by 322 wide), lblStatus2 (150 high by 322 wide) and lblStatus3 (12 high by 322 wide). The first and third are standard labels which sit above and below the second (top for 1 is 6, 2 is 30 and 3 is 186).
The second label (lblStatus2) has a white background, and a single border, with an opaque backstyle.
Here is the userform's activate event:
Code:
Private Sub UserForm_Activate()
Dim sSub As String: sSub = sSubName
Dim sArg As String: sArg = ""
Dim iPos As Integer
iPos = InStr(1, sSubName, ";")
If iPos > 0 Then
sSub = Left(sSubName, iPos - 1)
sArg = Mid(sSubName, iPos + 1)
If sArg = "" Then
Application.Run sSub
Else
Application.Run sSub, sArg
End If
Me.Repaint
Application.Wait Now + TimeValue("00:00:01")
sSubName = ""
Me.Hide
End Sub
The form also has a public property:
Code:
Public sSubName As String
When a ribbon button is clicked, it runs a procedure to load and initialise the userform:
Code:
Call RunWithUserInfo("RunMyEvents", "My App Name", "Ribbon Button 1")
Code:
Sub RunWithUserInfo(SubName As String, FormCaption As String, Optional DefaultMsgText1 As String = "", Optional DefaultMsgText2 As String = "", Optional DefaultMsgText3 As String = "")
Load xlt_frmUserInfo
With xlt_frmUserInfo
.Caption = FormCaption
.Controls("lblStatus1").Caption = DefaultMsgText1
.Controls("lblStatus2").Caption = DefaultMsgText2
.Controls("lblStatus3").Caption = DefaultMsgText3
.sSubName = SubName
.Show
.Repaint
End With
End Sub
Then, before each subsequent event that is run within the overall procedure (RunMyEvents), another call is made, e.g.:
Code:
Call UpdateUserInfoStatus(2, "Running the initialisation...")
Call EventName1
Call UpdateUserInfoStatus(2, "Loading the data...")
Call EventName2
...
Call UpdateUserInfoStatus(2, "Tidying up...")
Call EventName25
Code:
Sub UpdateUserInfoStatus(iLabel As Integer, Message As String)
With xlt_frmUserInfo
If .Controls("lblStatus" & Format(iLabel, "0")).Caption = "" Or iLabel = 3 Then
.Controls("lblStatus" & Format(iLabel, "0")).Caption = Message
Else
.Controls("lblStatus" & Format(iLabel, "0")).Caption = .Controls("lblStatus" & Format(iLabel, "0")).Caption & vbCrLf & Message
End If
.Repaint
End With
End Sub
The issue I have is that we are running many procedures as it loops through several iterations, and once the text in lblStatus2 gets longer than 15 lines, you can't see the progress. I tried switching to a ListBox, but that just added a scrollbar, when what I'd like is the top one to be removed each time a new one is added so you only ever see, say in this example, 15 lines.
I can't figure out how to add the lines, and then remove the top one each time! Or is there an easier/smarter way to do this?
Any help or advice gratefully received.
Many thanks
Martin