InputBox Function in Visual Basic .NET

In this article, I will explain you about InputBox Function in Visual Basic .NET.
  • 8356

InputBox Function

In Visual Basic .NET InputBox Function displays a prompt in a dialog box and waits for the user to write some text and click on the OK button. If the user clicks the OK button, the InputBox function will returns the contents to the text box. If the user clicks on the Cancel button, the function will return an empty string ("").The following code shows you the InputBox function. Drag a Button1and a TextBox control from the toolbox onto the form. Place the code below in the click event of the Button1.


Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs)Handles Button1.Click
        Dim str As String = InputBox("Enter you name")
        'Storing text entered in a string
        TextBox1.Text = str
        'Displaying string in the Textbox
End Class

When you click the Button1, the InputBox open and ask you to "Enter your name". The image below shows you the InputBox.


When you click OK of the InputBox it displays the text you entered in the TextBox control of the form. The image below displays output.



I hope this article will help you to understand about InputBox Function in Visual Basic .NET.


More Articles

© 2020 DotNetHeaven. All rights reserved.