- 1). Create a string variable to hold your message. The MsgBox() function displays text that you define regardless of the type of message. The following code creates a string with an alert for the user:
Dim strMessage as String
strMessage = "Are you sure you want to delete this object?" - 2). Create a title for the message box. When you receive a message box, the top title bar displays a title for the window. The string below is used to set a title for the window:
Dim strTitle as String
strTitle = "Application Confirmation" - 3). Set a style for the message box. Styles include a "Yes/No" confirmation box, a box that just displays an "Ok" button or a box that gives the user the ability to abort an action. For this example, the code below sets the style for a "Yes/No" message box.
Dim style as MsgBoxStyle
style = MsgBoxStyle.YesNo - 4). Display the message box for the user. Combining all the options created in the previous steps, you can now display the message box and retrieve the user's answer. The code below displays the message box:
Dim response as Integer
response = MsgBox(strMessage, style, strTitle)
previous post
next post