VBMAN.Toast - Notification Message Object
Overview
VBMAN.Toast provides non-blocking notification message display functionality, similar to Toast notifications in modern operating systems. Supports 9 display positions, 4 state styles, 2 themes, suitable for scenarios where user notification is needed without interrupting operations.
Core Features
- 9 Display Positions: Top-left, left-center, bottom-left, top-center, center, bottom-center, top-right, right-center, bottom-right
- Chain Calling: Supports fluent chain API design
- Auto Stacking: Non-center positions support automatic stacking display
- State Styles: Info, Success, Warning, Error four visual states
- Theme Switching: Supports Light/Dark themes
- Tag Management: Supports managing specific Toasts by tag name
- Event Notification: Provides count change and all-close events
Enum Types
EnumPos - Display Position
| Constant | Value | Description |
|---|---|---|
LeftTop | 10 | Top-left corner |
LeftCenter | 12 | Left-center (centered, no stacking) |
LeftBottom | 14 | Bottom-left corner |
CenterTop | 20 | Top-center |
Center | 22 | Center (centered, no stacking) |
CenterBottom | 24 | Bottom-center |
RightTop | 30 | Top-right corner |
RightCenter | 32 | Right-center (centered, no stacking) |
RightBottom | 34 | Bottom-right corner |
EnumState - Message State
| Constant | Value | Description |
|---|---|---|
Info | 1 | Info (blue) |
Success | 2 | Success (green) |
Warning | 3 | Warning (yellow) |
Danger | 4 | Error (red) |
EnumTheme - Theme
| Constant | Value | Description |
|---|---|---|
Light | 1 | Light theme |
Dark | 2 | Dark theme |
Chain Calling Methods
Pos
Set display position, supports chain calling.
Public Function Pos(p As EnumPos) As cToastExample:
' Display in top-right corner
VBMAN.Toast.Pos(RightTop).Show "Operation successful"
' Display in bottom-left corner
VBMAN.Toast.Pos(LeftBottom).Show "Download complete"State
Set message state, affects visual style.
Public Function State(s As EnumState) As cToastExample:
' Success notification
VBMAN.Toast.State(Success).Show "Save successful"
' Error notification
VBMAN.Toast.State(Danger).Show "Operation failed"
' Warning notification
VBMAN.Toast.State(Warning).Show "Please check"Theme
Set theme.
Public Function Theme(t As EnumTheme) As cToastExample:
' Dark theme
VBMAN.Toast.Theme(Dark).Show "Night mode notification"
' Light theme (default)
VBMAN.Toast.Theme(Light).Show "Normal notification"InstIndex
Manually set stack index (only supports non-center positions).
Public Function InstIndex(ByVal i As Long) As cToastDescription:
- Center positions (Center, LeftCenter, RightCenter) don't support stacking
- If this method is not called, system will automatically manage stack order
Example:
' Specify stack at position 2
VBMAN.Toast.Pos(RightTop).InstIndex(1).Show "First"
VBMAN.Toast.Pos(RightTop).InstIndex(2).Show "Second"Tag
Set Toast tag name for subsequent management.
Public Function Tag(ByVal Name As String) As cToastDescription:
- If tag is not set, system will auto-generate random tag
- Toasts with same tag won't be created repeatedly
Example:
' Set tag for later closing
VBMAN.Toast.Tag("upload_status").Show "Uploading..."
' Close Toast with specified tag
VBMAN.Toast.CloseMe "upload_status"Show
Display Toast notification, end of chain call.
Public Function Show(ByVal Content As String, Optional ByVal Delay As Long = 3000, Optional ByVal Title As String) As cToastParameters:
Content- Message contentDelay- Display duration (milliseconds, default 3000)Title- Message title (optional, non-center positions show "Notification" by default)
Example:
' Simple message
VBMAN.Toast.Show "Operation successful"
' With title and duration
VBMAN.Toast.Show "File save complete", 5000, "Success"
' Complete chain call
VBMAN.Toast _
.Pos(RightTop) _
.State(Success) _
.Theme(Light) _
.Tag("save_result") _
.Show "File saved successfully!", 3000, "Complete"Management Methods
CloseMe
Close Toast with specified tag.
Public Function CloseMe(ByVal Name As String) As BooleanReturn Value: Whether successfully closed
Example:
' Close Toast with specified tag
If VBMAN.Toast.CloseMe("upload_status") Then
Debug.Print "Closed"
End IfCloseAll
Close all Toasts.
Public Function CloseAll() As BooleanExample:
' Close all Toasts
VBMAN.Toast.CloseAll
' Call when form unloads
Private Sub Form_Unload(Cancel As Integer)
VBMAN.Toast.CloseAll
End SubExists
Check if Toast with specified tag exists.
Public Function Exists(ByVal Name As String) As BooleanExample:
' Check if exists
If VBMAN.Toast.Exists("upload_status") Then
Debug.Print "Upload status notification is showing"
End IfStatistics Properties
Count
Get total number of currently displayed Toasts.
Public Property Get Count() As LongExample:
Debug.Print "Currently " & VBMAN.Toast.Count & " Toasts are showing"ActiveKeys
Get collection of all active Toast tags.
Public Property Get ActiveKeys() As CollectionExample:
Dim keys As Collection
Set keys = VBMAN.Toast.ActiveKeys
Dim key As Variant
For Each key In keys
Debug.Print "Active Toast: " & key
Next keyEvents
OnToastCountChange
Triggered when Toast count changes.
Public Event OnToastCountChange(ByVal TagName As String, ByVal IsDelete As Boolean, ByVal CurrentCount As Long)Parameters:
TagName- Tag of changed ToastIsDelete- True=deleted, False=addedCurrentCount- Current total count
OnCloseAll
Triggered when all Toasts are closed.
Public Event OnCloseAll(ByVal closedCount As Long)Parameters:
closedCount- Number of Toasts closed
Comprehensive Examples
Example 1: Notifications at Different Positions
Private Sub ShowMultiPos()
' Top-right - Success notification
VBMAN.Toast.Pos(RightTop).State(Success).Show "Save successful", 2000
' Top-left - Info notification
VBMAN.Toast.Pos(LeftTop).State(Info).Show "New message", 3000
' Bottom-right - Warning notification
VBMAN.Toast.Pos(RightBottom).State(Warning).Show "Disk space low", 5000
' Center - Error notification (centered display, no stacking)
VBMAN.Toast.Pos(Center).State(Danger).Show "Operation failed!", 0, "Error"
End SubExample 2: Upload Progress Notification
Private Sub UploadFile()
Dim filePath As String
filePath = "C:\data.zip"
' Show start upload notification
VBMAN.Toast _
.Pos(RightTop) _
.State(Info) _
.Tag("upload") _
.Show "Uploading: " & filePath, 0, "Uploading"
' Simulate upload process
Dim i As Integer
For i = 0 To 100 Step 10
' Update progress...
DoEvents
Sleep 200
Next i
' Close upload notification, show complete
VBMAN.Toast.CloseMe "upload"
VBMAN.Toast _
.Pos(RightTop) _
.State(Success) _
.Show "Upload complete!", 3000, "Complete"
End SubExample 3: Batch Operation Notification
Private Sub BatchProcess()
Dim i As Integer
Dim successCount As Integer
Dim failCount As Integer
' Show start notification
VBMAN.Toast _
.Pos(CenterBottom) _
.State(Info) _
.Tag("batch") _
.Show "Starting batch processing...", 0
For i = 1 To 100
If ProcessItem(i) Then
successCount = successCount + 1
Else
failCount = failCount + 1
End If
' Update notification every 25 processed
If i Mod 25 = 0 Then
VBMAN.Toast.CloseMe "batch"
VBMAN.Toast _
.Pos(CenterBottom) _
.State(Info) _
.Tag("batch") _
.Show "Processed: " & i & "/100", 0
DoEvents
End If
Next i
' Close progress notification
VBMAN.Toast.CloseMe "batch"
' Show result
If failCount = 0 Then
VBMAN.Toast _
.Pos(RightTop) _
.State(Success) _
.Show "All processed successfully!", 3000
Else
VBMAN.Toast _
.Pos(RightTop) _
.State(Warning) _
.Show "Success: " & successCount & ", Failed: " & failCount, 5000
End If
End SubExample 4: Auto Stack Effect
Private Sub AutoStackDemo()
Dim i As Integer
' Automatically stack and display multiple messages in top-right corner
For i = 1 To 5
VBMAN.Toast _
.Pos(RightTop) _
.State(Info) _
.Show "Message " & i, 3000 + i * 1000
Sleep 500
Next i
End SubExample 5: Server-side Use (Avoid MsgBox Blocking)
Public Sub HandleServerMessage(Data As cJson)
If Common.IsServer = True Then
' Server-side avoids using MsgBox blocking, use Toast instead
VBMAN.Toast _
.Pos(RightTop) _
.State(Info) _
.Show Data("Content"), 60000, Data("Title")
Exit Sub
End If
End SubExample 6: Dark Theme Notification
Private Sub DarkModeToast()
' Dark theme success notification
VBMAN.Toast _
.Pos(RightBottom) _
.State(Success) _
.Theme(Dark) _
.Show "Night mode enabled", 2000
' Dark theme warning notification
VBMAN.Toast _
.Pos(LeftBottom) _
.State(Warning) _
.Theme(Dark) _
.Show "Low battery", 5000, "System"
End SubUsage Suggestions
Position Selection:
- Normal notifications: Top-right (RightTop)
- Important messages: Center (Center)
- Auxiliary info: Bottom-center (CenterBottom)
Center Position Limitations:
- Center, LeftCenter, RightCenter don't support stacking
- Only one centered Toast can be displayed at a time
Tag Management:
- Toasts that need to be closed later must have tags set
- Toasts with same tag won't be created repeatedly
Duration Settings:
- Normal notifications: 2000-3000ms
- Important messages: 5000ms or longer
- Manual close needed: set to 0
Resource Cleanup:
- Call
CloseAllwhen form unloads - Avoid Toast residue causing memory leaks
- Call
Notes
- Toast is non-modal, won't block user operations
- Display duration unit is milliseconds (1 second = 1000 milliseconds)
- Supports using
vbCrLffor multi-line content display - Centered position Toasts will overlay display, not stack
- On Windows server may not display UI properly, recommended to use with logs