1

My A-Level programming project is unfortunately in vb.net.

I remembered that InputBox was a method, so I tried it. It came back as undeclared.

Eventually I found a forum where someone mentioned that if you import the Microsoft.VisualBasic namespace you can use it again, but apparently that's been removed aswell ('InputBox' is not a member of 'Microsoft.VisualBasic').

I'm lost as to why Microsoft decided to remove InputBox, but keep MessageBox seeing as though they're both as useful as each other - even for a language as old as VB.

To get round this, would I create a form dedicated to collecting user inputs? There must be an better way to get InputBox back, I just can't seem to find it.

Thank you.


Edit for replication of my error:

'create a normal forms app (I'm using .NET Core 3.0)
Public Class frmExample
   Private Sub frmExample_Load(sender as Object, e as EventArgs) Handles MyBase.Load
      Dim userInput as string
      userInput = Interaction.InputBox("Example") 'InputBox is not a member of Interaction
      userInput = Microsoft.VisualBasic.InputBox("Example") 'InputBox is not a member of Microsoft.VisualBasic
   End Sub
End Class
Joe Moore
  • 2,031
  • 2
  • 8
  • 29
  • It takes five minutes (plus testing :) to build a much more beautiful dialog Form that returns a string. -- Assuming this kind of thing has actually any use today. – Jimi Aug 23 '21 at 12:25
  • InputBox still exists in the Microsoft.VisualBasic assembly inside the Interaction Class https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.interaction.inputbox?view=net-5.0 – Steve Aug 23 '21 at 12:26
  • @Steve I also looked at that article, but InputBox is not a member of Interaction. - I will edit my question to allow replication of my error. – Joe Moore Aug 23 '21 at 12:46
  • 2
    @JoeMoore: Cannot reproduce, your second line compiles correctly on my system and on dotnetfiddle: https://dotnetfiddle.net/bViVnG – Heinzi Aug 23 '21 at 12:54
  • @Heinzi i'm lost then https://gyazo.com/642dfbe979b3ed38c706ec3a4db54b6f - I cant work out why it isnt compiling. Going to restart my IDE. Edit: did not change – Joe Moore Aug 23 '21 at 12:58
  • Something unclear here. You say _(I'm using VB.NET 3.0)_ but the first version of VB.NET is version 7.0 released in 2002. – Steve Aug 23 '21 at 13:06
  • Thats odd, I must be mistaken if that is the case, but my `Target framework` in my project properties is `.NET Core 3.0` - I appear to have mistaken `VB.net` and `.NET Core` – Joe Moore Aug 23 '21 at 13:08
  • .Net Core 3.0 is the version of the framework you are using, not the version of vb.net. – Mary Aug 23 '21 at 13:10
  • 1
    I can't test with Core 3.0 (end of support) but in 5.0 it works as expected – Steve Aug 23 '21 at 13:14
  • Ah, that explains it. I'll have to create a form then since my school only uses Core 3.0 - god knows why. Thank you for all the help. – Joe Moore Aug 23 '21 at 13:15
  • 1
    Ahh, trying to switch the [Microsoft Page](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.interaction.inputbox?view=net-5.0&viewFallbackFrom=netcore-3.0) to Net Core 3.0, gives an hint: _The requested page is not available for .NET Core 3.0. You have been redirected to the newest product version this page is available for._ – Steve Aug 23 '21 at 13:15
  • 3
    You are under some misconceptions. `InputBox` is basically part of VB. `MessageBox` is not. You are thinking of `MsgBox`. Both `InputBox` and `MsgBox` are functions that were migrated from VB6 to VB.NET to ease migration between languages. The `MessageBox` class is 100% .NET. The `InputBox` function is garbage and you should never use it, other than maybe for quick and dirty tests and demos. `MsgBox` is also garbage and `MessageBox.Show` should be used in preference. – jmcilhinney Aug 23 '21 at 15:42
  • *both as useful as each other* - by *useful* do you mean "should never be used in any modern user interface, ever"? If I wanted my workflow to be interrupted by blocking dialogs and annoying bong sounds constantly, I'd use a Symbian phone – Caius Jard Aug 24 '21 at 05:24

1 Answers1

1

In .NET Core 3.0 InputBox is not a method. This works as expected, however, in .NET Core 5.0.

In order to fix this: Change your Target Framework in Project Properties to .NET Core 5.0.

Or alternatively do what @Jimi suggested which was to simply create an InputBox form yourself.

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
Joe Moore
  • 2,031
  • 2
  • 8
  • 29