Home
Do you know how to format your MessageBox code?
  v1.0 Posted at 26/04/2018 9:14 AM by Tiago Araujo

You should always write each parameter of MessageBox in a separate line. So it will be more clear to read in the code. Format your message text in code as you want to see on the screen.

​Private Sub ShowMyMessage()
MessageBox.Show("Are
you sure you want to delete the team project """ + strProjectName
+ """?" + Environment.NewLine + Environment.NewLine + "Warning:
Deleting a team project cannot be undone.", strProductName + "
" + strVersion(), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)

Figure: Bad example of MessageBox code format​

Private Sub ShowMyMessage()
MessageBox.Show( _
"Are you sure you want to delete the team project """ + strProjectName + """?"
_ + Environment.NewLine _ +
Environment.NewLine _ +
"Warning: Deleting a team project cannot be undone.", _
strProductName + " " + strVersion(), _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Warning, _
MessageBoxDefaultButton.Button2)
End Sub

Figure: Good example of MessageBox code format​​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.