Problems with InputBox

Mal Ba

Member
Joined
May 13, 2021
Messages
5
Programming Experience
10+
I am trying to upgrade an old visual basic program and have hit one problem.

The use of InputBox() fails with "InputBox is not declared". Error BC30451
Various sources say it is a member variously of Microsoft.VisualBasic or Microsoft.VisualBasic.Interaction namespaces
But
Dim s as string= Microsoft.VisualBasic.Inputbox("Enter organisation name")
and
Dim s as string= Microsoft.VisualBasic.Interaction.Inputbox("Enter organisation name")
both fail with error BC30456 telling me that 'InputBox' is not a member of either of those namespaces

Is InputBox still usable and how do I find it? I really don't want to have to code up a new form for this unless I have to.

Thanks
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,493
Location
Sydney, Australia
Programming Experience
10+
InputBox is not a member of a namespace. It can't be, because it's not a type. Only types can be members of namespaces. Microsoft.VisualBasic is a namespace and Interaction is a module that is a member of that namespace. InputBox is a method that is a member of that module. Because module members, unlike class members, can be referred to without qualification by the type name. That means that the fully qualified name is Microsoft.VisualBasic.Interaction.InputBox but you can also use Microsoft.VisualBasic.InputBox and, if you have imported the Microsoft.VisualBasic namespace, which is done by default in every VB project that I've ever seen, you can also use Interaction.InputBox or just InputBox.

Generally speaking, you can just use InputBox unqualified in a WinForms project. If you can't then it's because you have done something odd to your project. It's hard for us to just guess what that is. Even .NET 5.0 projects support it. Even .NET 5.0 Console apps support it. You need to work out what you've broken and how. I suggest that you try creating a fresh project and see whether it works there. If it does, it's time to start comparing the two to see what the differences are.
 

Mal Ba

Member
Joined
May 13, 2021
Messages
5
Programming Experience
10+
InputBox is not a member of a namespace. It can't be, because it's not a type. Only types can be members of namespaces. Microsoft.VisualBasic is a namespace and Interaction is a module that is a member of that namespace. InputBox is a method that is a member of that module. Because module members, unlike class members, can be referred to without qualification by the type name. That means that the fully qualified name is Microsoft.VisualBasic.Interaction.InputBox but you can also use Microsoft.VisualBasic.InputBox and, if you have imported the Microsoft.VisualBasic namespace, which is done by default in every VB project that I've ever seen, you can also use Interaction.InputBox or just InputBox.

Generally speaking, you can just use InputBox unqualified in a WinForms project. If you can't then it's because you have done something odd to your project. It's hard for us to just guess what that is. Even .NET 5.0 projects support it. Even .NET 5.0 Console apps support it. You need to work out what you've broken and how. I suggest that you try creating a fresh project and see whether it works there. If it does, it's time to start comparing the two to see what the differences are.
As I have said Microsoft.VisualBasic.Interaction.InputBox ,e Microsoft.VisualBasic.InputBox , Interaction.InputBox and InputBox all do not work.

I have tried it in a brand new open project. All of these flag an error. The first and thirdreport that InputBox is not a member of Interaction (error BC30456). The second says InputBox is not a member of VisualBasic (error BC30456.). The last reports that InputBox is not declared. InputBox appears nowhere in a search of the Object Browser.

Any suggestions?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,493
Location
Sydney, Australia
Programming Experience
10+
Please provide us with the exact, detailed steps of what you did so that we can try to reproduce the issue. Either your VS installation is broken is deficient in some way or you are doing something wrong that you're not actually telling us about. It's impossible to tell which from the information you have provided. We need all the specific details.
 

Mal Ba

Member
Joined
May 13, 2021
Messages
5
Programming Experience
10+
Exact steps
1. Open a new project
2. In a blank form create a button
3.
VB.NET:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim s As String = InputBox("Enter value")
    End Sub
That's it. At this point InputBox is given a wiggly red line under it with the error message as given above: BC30451: 'InputBox' is not declared . It may be inaccessible due to its protection level.
If I replace InputBox by Microsoft.VisualBasic.InputBox, I get the error message {}Namespace.Microsoft.VisualBasic. BC30456: 'InputBox' is not a member of Microsoft.VisualBasic'.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,493
Location
Sydney, Australia
Programming Experience
10+
Exact steps
1. Open a new project
Well, that's an immediate fail. "Exact" means exact. There are many, many different project templates in VS so "a new project" only gets you so far. Presumably it was a Windows Forms Application project but was it targeting .NET 5.0, an earlier version of .NET Core or some version of .NET Framework? Which one and which version?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,493
Location
Sydney, Australia
Programming Experience
10+
I just tried that with WinForms App projects targeting .NET 5.0 and .NET Framework 4.8 and it worked fine in both, as I expected. I'm sticking with my initial impression that your VS installation is broken somehow and you should perform a repair.
 

Mal Ba

Member
Joined
May 13, 2021
Messages
5
Programming Experience
10+
This is a newly downloaded version of everything - totally vanilla - nothing modified. According to the VS help box it is Version 16.9.4 (c) 2021 Microsoft Corporation Microsoft .Net framework Version 4.8.04084 (c) 2021 Microsoft Corporation. The project is a WinFormsApp.

Full Copy info from the help box
Microsoft Visual Studio Community 2019
Version 16.9.4
VisualStudio.16.Release/16.9.4+31205.134
Microsoft .NET Framework
Version 4.8.04084
Installed Version: Community
ASP.NET and Web Tools 2019 16.9.693.2781
ASP.NET and Web Tools 2019
Azure App Service Tools v3.0.0 16.9.693.2781
Azure App Service Tools v3.0.0
C# Tools 3.9.0-6.21160.10+59eedc33d35754759994155ea2f4e1012a9951e3
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
IntelliCode Extension 1.0
IntelliCode Visual Studio Extension Detailed Info
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers
NuGet Package Manager 5.9.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit NuGet documentation
ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info
TypeScript Tools 16.0.30201.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 3.9.0-6.21160.10+59eedc33d35754759994155ea2f4e1012a9951e3
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 16.9.0-beta.21102.9+7ce7132f1459095e635194d09d6f73265352029a
Microsoft Visual F# Tools
Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,493
Location
Sydney, Australia
Programming Experience
10+
Very little of that is actually relevant. That you're using VS 16.9.4 is relevant but, beyond that, what matters is your project., like what project template you actually selected and what framework version it targets. That said, in this case it doesn't matter. As I've already stated, InputBox works regardless. If it's not working for you then either you have done something to cause it that you haven't told us about or your VS install is broken. I've told you how to at least attempt to address the latter and we can't help you with the former for the very reason that you haven't told us about what you did. For the record, I think it's the latter case.
 

Mal Ba

Member
Joined
May 13, 2021
Messages
5
Programming Experience
10+
You complained last time I didn't give you enough information so obviously I do not know what is relevant and what is not. So I gave you everything. I said it was a "WinFormsApp" template: I simply clicked on that template on the newly installed version of the above version of Visual Studio. What more template details do you need? I don't know what more I can give you, but if you tell me specifically how to get more information about the "WinFormApp" template I will get it. I have not done anything else that I would not tell you about. It is simple as that. New download, new WinFormsApp project, that code, does not work.

If it is broken I am not sure how to address that. I have not broken anything, I have not changed any settings, It is a basic install., So can you give me some details? I can't see a repair function in Visual Studios. Do I just reinstall it again? I can't see that doing anything different from the last re-install but I guess I could do that.
 

kiirukun

New member
Joined
Jun 19, 2021
Messages
1
Programming Experience
5-10
I think the problem is with the framework that you are using.

Under .Net Core 3.1. this shows up, but it should work under 5.0
1624126932508.png


To change it just go under Project > properties > application > Target Framework
 
Top Bottom