Scarth Scarth - 14 days ago 6
Vb.net Question

Overload resolution failed when attempting to display messagebox

I'm having an issue writing in VB 2010 with the following code.

Public Sub about(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show("Omega Management System © Shelby Taylor 2013 ******@gmail.com", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub


I have this code in a module that I'm using as a general purpose 'holder' to hold some database connections behind the scenes of my program. I would like to make a messagebox subprocedure which will display my contact information should the user click a button, in which case I will call upon this procedure and display the messagebox.

I am receiving the following error.

Error 1 Overload resolution failed because no accessible 'Show' can be called without a narrowing conversion:
'Public Shared Function Show(owner As System.Windows.Forms.IWin32Window, text As String, caption As String) As System.Windows.Forms.DialogResult': Argument matching parameter 'owner' narrows from 'String' to 'System.Windows.Forms.IWin32Window'.
'Public Shared Function Show(owner As System.Windows.Forms.IWin32Window, text As String, caption As String) As System.Windows.Forms.DialogResult': Argument matching parameter 'text' narrows from 'System.Windows.Forms.MessageBoxButtons' to 'String'.
'Public Shared Function Show(owner As System.Windows.Forms.IWin32Window, text As String, caption As String) As System.Windows.Forms.DialogResult': Argument matching parameter 'caption' narrows from 'System.Windows.Forms.MessageBoxIcon' to 'String'.
'Public Shared Function Show(text As String, caption As String, buttons As System.Windows.Forms.MessageBoxButtons) As System.Windows.Forms.DialogResult': Argument matching parameter 'caption' narrows from 'System.Windows.Forms.MessageBoxButtons' to 'String'.
'Public Shared Function Show(text As String, caption As String, buttons As System.Windows.Forms.MessageBoxButtons) As System.Windows.Forms.DialogResult': Argument matching parameter 'buttons' narrows from 'System.Windows.Forms.MessageBoxIcon' to 'System.Windows.Forms.MessageBoxButtons'. M:\oms\omega_managment_system\WindowsApplication1\globalStructures.vb 21 9 Omega Managment System


And I don't understand what is happening. Could someone please explain what the issue is, and how to fix it?

Thank you.

Answer

The error message tells all:

Public Shared Function Show(text As String, caption As String, _
buttons As System.Windows.Forms.MessageBoxButtons) ...
Argument matching parameter 'caption' narrows from 
  'System.Windows.Forms.MessageBoxButtons' to 'String'.

You have to follow those formats. The second arg should be a string (the caption) but you are passing the button info. There are multiple ways it can be called (so the multiple msgs) but you need to follow one of them

Comments