question

GiovanniConte-6670 avatar image
0 Votes"
GiovanniConte-6670 asked XingyuZhao-MSFT commented

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

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!

dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

OlafHelper-2800 avatar image
1 Vote"
OlafHelper-2800 answered XingyuZhao-MSFT commented

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?


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you Olaf,
I'm using App Windows Forms with Visual Basic. I'm trying to convert old VB6 code into new VB 2019 code. In all the Apps I've converted, MsgBox (old VB Style) worked well. Only in the App I'm currently converting MsgBox (old style) does not. And I wonder why. Of course, now I'm using MessageBox.Show (new style). However, this and many other issues, I find them all so frustrating.
Thank you again,
Giovanni

0 Votes 0 ·

Hi @GiovanniConte-6670 ,

now I'm using MessageBox.Show (new style).

Is the exception avoided when using 'MessageBox.Show' ?

0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered GiovanniConte-6670 commented

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



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Many thanks, Karen
I will insert your code in my projects.
Thank you again,
Giovanni

0 Votes 0 ·