From dfa0dfbdfa67533f62650954f68c7f42e2dbb32d Mon Sep 17 00:00:00 2001 From: Adit Sheth Date: Tue, 28 Jan 2025 06:15:35 -0800 Subject: [PATCH] Fixed bug 36231. (#44556) Co-authored-by: Adit Sheth --- .../data-types/how-to-declare-a-structure.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/visual-basic/programming-guide/language-features/data-types/how-to-declare-a-structure.md b/docs/visual-basic/programming-guide/language-features/data-types/how-to-declare-a-structure.md index 1db092a270abd..435ca92c6e9f5 100644 --- a/docs/visual-basic/programming-guide/language-features/data-types/how-to-declare-a-structure.md +++ b/docs/visual-basic/programming-guide/language-features/data-types/how-to-declare-a-structure.md @@ -44,11 +44,24 @@ You begin a structure declaration with the [Structure Statement](../../../langua salary *= raise End Sub Public Event salaryReviewTime() + + ' Method to raise the event + Public Sub TriggerSalaryReview() + RaiseEvent salaryReviewTime() + End Sub End Structure ``` - The `salary` field in the preceding example is `Private`, which means it is inaccessible outside the structure, even from the containing class. However, the `giveRaise` procedure is `Public`, so it can be called from outside the structure. Similarly, you can raise the `salaryReviewTime` event from outside the structure. - + The `salary` field in the preceding example is `Private`, which means it is inaccessible outside the structure, even from the containing class. However, the `giveRaise` procedure is `Public`, so it can be called from outside the structure. Similarly, you can raise the `salaryReviewTime` event indirectly by calling a method within the structure that raises it. For example: + + ```vb + Public Sub TriggerSalaryReview() + RaiseEvent salaryReviewTime() + End Sub + ``` + + This allows you to control how and when the event is raised while keeping the event inaccessible directly from outside the structure. + In addition to variables, `Sub` procedures, and events, you can also define constants, `Function` procedures, and properties in a structure. You can designate at most one property as the *default property*, provided it takes at least one argument. You can handle an event with a [Shared](../../../language-reference/modifiers/shared.md)`Sub` procedure. For more information, see [How to: Declare and Call a Default Property in Visual Basic](../procedures/how-to-declare-and-call-a-default-property.md). ## See also