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

Giovanni Conte 56 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!

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Olaf Helper 43,246 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,386 Reputation points
    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