Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit eef77ca

Browse files
authored
Update raiseevent-statement.md
`Text1.Refresh` and `Text2.Refresh` don't compile since the member `Refresh` doesn't exist on `TextBox`. They cause compilation errors otherwise. `Form_Load` should be `UserForm_Initialize`. `dblSecond` is declared, but never used. Indented according to default VBA settings. `vbNullString` used in favor of `""`. `ExampleEvent` added an sub was previously nameless.
1 parent 02e0617 commit eef77ca

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

VBA/Language-Reference-VBA/articles/raiseevent-statement.md

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ ms.date: 06/08/2017
1111

1212
# RaiseEvent Statement
1313

14-
Fires an event declared at [module level](vbe-glossary.md) within a[class](vbe-glossary.md), form, or document.
14+
Fires an event declared at [module level](vbe-glossary.md) within a [class](vbe-glossary.md), form, or document.
1515

1616
**Syntax**
1717

18-
**RaiseEvent**_eventname_ [ **(**_argumentlis_ t **)** ]
18+
**RaiseEvent**_eventname_ [ **(** argumentlist **)** ]
1919

20-
The required _eventname_ is the name of an event declared within the[module](vbe-glossary.md) and follows Basic variable naming conventions.
20+
The required _eventname_ is the name of an event declared within the [module](vbe-glossary.md) and follows Basic variable naming conventions.
2121
The **RaiseEvent** statement syntax has these parts:
2222

2323

2424
|**Part**|**Description**|
2525
|:-----|:-----|
2626
| _eventname_|Required. Name of the event to fire.|
27-
| _argumentlist_|Optional. Comma-delimited list of [variables](vbe-glossary.md), [arrays](vbe-glossary.md), or [expressions](vbe-glossary.md) The _argumentlist_ must be enclosed by parentheses. If there are no[arguments](vbe-glossary.md), the parentheses must be omitted.|
27+
| _argumentlist_|Optional. Comma-delimited list of [variables](vbe-glossary.md), [arrays](vbe-glossary.md), or [expressions](vbe-glossary.md) The _argumentlist_ must be enclosed by parentheses. If there are no [arguments](vbe-glossary.md), the parentheses must be omitted.|
2828
**Remarks**
2929
If the event has not been declared within the module in which it is raised, an error occurs. The following fragment illustrates an event declaration and a procedure in which the event is raised.
3030

@@ -34,13 +34,13 @@ If the event has not been declared within the module in which it is raised, an e
3434
' Declare an event at module level of a class module
3535
Event LogonCompleted (UserName as String)
3636

37-
Sub
37+
Sub ExampleEvent()
3838
' Raise the event.
3939
RaiseEvent LogonCompleted ("AntoineJan")
4040
End Sub
4141
```
4242

43-
If the event has no arguments, including empty parentheses, in the **RaiseEvent**, invocation of the event causes an error. You can't use **RaiseEvent** to fire events that are not explicitly declared in the module. For example, if a form has a Click event, you can't fire its Click event using **RaiseEvent**. If you declare a Click event in the[form module](vbe-glossary.md), it shadows the form's own Click event. You can still invoke the form's Click event using normal syntax for calling the event, but not using the **RaiseEvent** statement.
43+
If the event has no arguments, including empty parentheses, in the **RaiseEvent**, invocation of the event causes an error. You can't use **RaiseEvent** to fire events that are not explicitly declared in the module. For example, if a form has a Click event, you can't fire its Click event using **RaiseEvent**. If you declare a Click event in the [form module](vbe-glossary.md), it shadows the form's own Click event. You can still invoke the form's Click event using normal syntax for calling the event, but not using the **RaiseEvent** statement.
4444
Event firing is done in the order that the connections are established. Since events can have **ByRef** parameters, a process that connects late may receive parameters that have been changed by an earlier event handler.
4545

4646
## Example
@@ -61,30 +61,30 @@ Option Explicit
6161

6262
Private WithEvents mText As TimerState
6363

64-
Private Sub Command1_Click()
65-
Text1.Text = "From Now"
66-
Text1.Refresh
67-
Text2.Text = "0"
68-
Text2.Refresh
69-
Call mText.TimerTask(9.84)
70-
End Sub
64+
Private Sub Command1_Click()
65+
Text1.Text = "From Now"
66+
Text2.Text = "0"
67+
68+
mText.TimerTask 9.58
69+
End Sub
7170

72-
Private Sub Form_Load()
73-
Command1.Caption = "Click to Start Timer"
74-
Text1.Text = ""
75-
Text2.Text = ""
76-
Label1.Caption = "The fastest 100 meters ever run took this long:"
77-
Set mText = New TimerState
78-
End Sub
71+
Private Sub UserForm_Initialize()
72+
Command1.Caption = "Click to start Timer"
73+
Text1.Text = vbNullString
74+
Text2.Text = vbNullString
75+
Label1.Caption = "The fastest 100 meters ever run took this long:"
76+
Set mText = New TimerState
77+
End Sub
78+
7979

80-
Private Sub mText_ChangeText()
81-
Text1.Text = "Until Now"
82-
Text2.Text = "9.84"
83-
End Sub
80+
Private Sub mText_ChangeText()
81+
Text1.Text = "Until Now"
82+
Text2.Text = "9.58"
83+
End Sub
8484

85-
Private Sub mText_UpdateTime(ByVal dblJump As Double)
86-
Text2.Text = Str(Format(dblJump, "0"))
87-
DoEvents
85+
Private Sub mText_UpdateTime(ByVal jump As Double)
86+
Text2.Text = Str$(Format(jump, "0"))
87+
DoEvents
8888
End Sub
8989
```
9090

@@ -98,22 +98,21 @@ Option Explicit
9898
Public Event UpdateTime(ByVal dblJump As Double)
9999
Public Event ChangeText()
100100

101-
Public Sub TimerTask(ByVal Duration As Double)
102-
Dim dblStart As Double
103-
Dim dblSecond As Double
104-
Dim dblSoFar As Double
105-
dblStart = Timer
106-
dblSoFar = dblStart
107-
108-
Do While Timer < dblStart + Duration
109-
If Timer - dblSoFar >= 1 Then
110-
dblSoFar = dblSoFar + 1
111-
RaiseEvent UpdateTime(Timer - dblStart)
112-
End If
113-
Loop
114-
115-
RaiseEvent ChangeText
116-
101+
Public Sub TimerTask(ByVal duration As Double)
102+
Dim start As Double
103+
start = Timer
104+
105+
Dim soFar As Double
106+
soFar = start
107+
108+
Do While Timer < start + duration
109+
If Timer - soFar >= 1 Then
110+
soFar = soFar + 1
111+
RaiseEvent UpdateTime(Timer - start)
112+
End If
113+
Loop
114+
115+
RaiseEvent ChangeText
117116
End Sub
118117
```
119118

0 commit comments

Comments
 (0)