I used to use a MessageBox as well. I switched to System.DebugLog though. But, I occasionally I still use it. But a little bit customized though.
If you prefer the MessageBox way, it might be useful to create a public function instead. I sometimes forgot to get get rid if all the debug messages.
If you create a public function, you can include an “If DebugBuild Then” condition. So, the message only appears when you debug your app.
Additionally, you can make the Message function a little bit more flexible by using a Parameter Array. That way, you can pass multiple message lines easier.
Function MyMessage( ParamArray Message() As String )
If Not DebugBuild Then Return // If you don't run the app in debug mode, no message will be shown.
If Message.Count = 0 Then Return // if no message value is passed, no message will be shown.
MessageBox String.FromArray( Message, EndOfLine ) // This will display the message values as multiple lines.
End Function
You can simply call your custom function like this:
MyMessage "Error found", "CurrentMethodName", "More detailed explanation"
When your final build hits this last line of code, nothing will happen.
But when you run the app in debug mode, within the IDE, a MessageBox will open with Three lines of code:
Error found
<name of the method, from where the function is called>
More detailed explanation
Disclaimer:
I didn’t test the above code, since I am not with my IDE now. But, I think it should work. I use it all the time.