Visual Basic 2019: MsgBox() doesn't work.

Giovanni Conte 66 Reputation points
2021-06-29T12:27:43.237+00:00

For the first time MsgBox() doesn't work. Error BC30451 (In italian: MsgBox non dichiarato. Potrebbe essere inaccessibile a causa del livello di protezione - something like MsgBox not declared. Could be inaccessible because of level protection). Kindly, help me!

Developer technologies | VB
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Olaf Helper 47,441 Reputation points
    2021-06-29T12:46:20.16+00:00

    That's a bit to less on informations.
    Which project type are you using?Is Is a reference/Import for Microsoft.VisualBasic set?

    And why do you use old VB style MsgBox and not the common MessageBox Class?

    1 person found this answer helpful.

  2. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-06-29T19:12:52.447+00:00

    You can always make your own e.g.

    Add this module to your project (add more wrappers as you see fit)

    Public Module Dialogs
        Public Function Question(Text As String) As Boolean
            Return (MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = MsgBoxResult.Yes)
        End Function
        Public Function Question(Text As String, Title As String) As Boolean
            Return (MessageBox.Show(Text, Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = MsgBoxResult.Yes)
        End Function
        Public Sub MsgBox(Text As String)
            MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        End Sub
        Public Sub MsgBox(Text As String, Title As String)
            MessageBox.Show(Text, Title, MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        End Sub
    End Module
    

    Use it

    Public Class Form1
        Private Sub MsgBoxButton_Click(sender As Object, e As EventArgs) Handles MsgBoxButton.Click
            MsgBox("Simple")
    
            If Question("Continue?") Then
                MsgBox("Yes")
            Else
                MsgBox("No")
            End If
        End Sub
    End Class
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.