Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2021, 04:14 AM
LQuinn LQuinn is offline best practices for message handling between subroutines? Windows 10 best practices for message handling between subroutines? Office 2019
Novice
best practices for message handling between subroutines?
 
Join Date: Jan 2021
Location: Western Australia
Posts: 20
LQuinn is on a distinguished road
Default best practices for message handling between subroutines?

Hi all, I've spent a lot of time googling as well as searching here, hoping someone could point me in the right direction for best practices on message handling please?
More of a soft concept search rather than a specific search for which methods and properties are exposed by any particular item, so not getting much joy on search results

I develop VBA to process documents that have been handed around multiple different users, all with their own interpretation and styles, so I remediate, normalise and then standardise document content - all in modular subroutines

What I'm looking for is advice on how to handle passing status messages, so all the routines run and then upon completion I can present a single message that has content from each subroutine (if required)

Thanks in advance
Reply With Quote
  #2  
Old 01-06-2021, 12:49 PM
eduzs eduzs is offline best practices for message handling between subroutines? Windows 10 best practices for message handling between subroutines? Office 2019
Expert
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

If you mean "passing status messages" as passing variables values, I imagine two possibilities, maybe:
Pass variables as arguments on a sub or a function.
Declare variables as Public (within project) or Private (within module).
Reply With Quote
  #3  
Old 01-06-2021, 04:58 PM
LQuinn LQuinn is offline best practices for message handling between subroutines? Windows 10 best practices for message handling between subroutines? Office 2019
Novice
best practices for message handling between subroutines?
 
Join Date: Jan 2021
Location: Western Australia
Posts: 20
LQuinn is on a distinguished road
Default

Quote:
Originally Posted by eduzs View Post
If you mean "passing status messages" as passing variables values, I imagine two possibilities, maybe:
Pass variables as arguments on a sub or a function.
Declare variables as Public (within project) or Private (within module).
Thanks, I've tried playing around with that but have asked here because I think there must be a better way
Reply With Quote
  #4  
Old 02-10-2021, 07:52 PM
LQuinn LQuinn is offline best practices for message handling between subroutines? Windows 10 best practices for message handling between subroutines? Office 2019
Novice
best practices for message handling between subroutines?
 
Join Date: Jan 2021
Location: Western Australia
Posts: 20
LQuinn is on a distinguished road
Default

ok, so it's taken a while because i'm no expert, but have managed to answer my own question

Code:
Public varDebug As Variant
Public Function saveMyDebugValue(DebugValue As Variant) As Long
'
' https://social.msdn.microsoft.com/Forums/office/en-US/5c2a83cf-0596-41a2-9f42-e64cc6b1e556/immediate-window-memory-limitation?forum=accessdev
'
    Dim I As Long
    If IsEmpty(varDebug) Then
        ReDim varDebug(0 To 0)
    Else
        ReDim Preserve varDebug(LBound(varDebug) To UBound(varDebug) + 1)
    End If
    I = UBound(varDebug)
    varDebug(I) = DebugValue
    saveMyDebugValue = I
End Function
clear the array before using it:
Code:
ReDim varDebug(0 To 0)
write to the array from various different routines:
Code:
saveMyDebugValue Now
saveMyDebugValue "Clean up document"
write the output from the array:
Code:
Write_MyDebugValue
my function to get the output from the array when complete:
Code:
Private Function Write_MyDebugValue()
'
' write log output to new document
'
    Dim varCounter As Variant
    Dim strOutPut As String
    Dim objDocTarget As Document
    
   ' For Each varCounter In varDebug
    For varCounter = 0 To UBound(varDebug)
        strOutPut = strOutPut & varDebug(varCounter) & vbCrLf
    Next varCounter
    'MsgBox strOutPut
    
    Set objDocTarget = Documents.Add
    
    objDocTarget.Range = ""

    With objDocTarget.Range
        .Font.Size = 9
        .Font.Name = "Arial"
        ' RGB value for 80% grey
        .Font.TextColor = RGB(80, 84, 77)
        '.InsertParagraphAfter
        '.InsertAfter "====================================================================================="
        .Text = strOutPut
        '.InsertAfter strOutPut
    End With
    
    Set varCounter = Nothing
    Set objDocTarget = Nothing
    
End Function
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handling message box prompts robert bristow Word VBA 2 07-10-2016 10:41 AM
best practices for message handling between subroutines? Images in Documents best practices liamnacuac Drawing and Graphics 1 03-29-2016 04:11 PM
best practices for message handling between subroutines? PivotTable best Practices lnicely@nvcc.edu Excel 1 07-13-2015 08:03 AM
Floor maps and best practices healthpointe Visio 0 07-10-2012 10:45 AM
Copying tables between Word documents best practices? dylane Word Tables 0 12-18-2008 12:21 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft