VB.Net - Syntax

Sub DelegateMethod1(ByVal sMessage As String) 
End Sub

Sub DelegateMethod2(ByVal sMessage As String)
End Sub

Public Delegate Sub Del_MyDelegate(ByVal sMessage As String)

Dim delMyDelegate As Del_MyDelegate1
delMyDelegate = New Del_MyDelegate(AddressOf DelegateMethod1)

Shared Delegates

Public Delegate Function Del_AskQuestion(ByVal sMessage As String) As Boolean 

Sub Main()
   Dim delAskQuestion As Del_AskQuestion

   delAskQuestion = New Del_AskQuestion(AddressOf MessageType.AskYesNo)

   If delAskQuestion.Invoke("Do you want to save this file ?") = True Then

   End If
End Sub

This class contains a shared function that returns True if the user answers Yes to the question.

Public Class MessageType 

   Public Shared Function AskYesNo(ByVal sMessage As String) As Boolean
      Dim answer As objMsgBoxResult

      objanswer = MsgBox(sMessage, MsgBoxStyle.YesNo Or MsgBoxStyle.Question)

      AskYesNo = (objanswer = MsgBoxResult.Yes)
   End Function
End Class

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrev