Input Box in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson explores InputBox dialog and demonstrates how you can use it in your Visual Basic applications.

When you need to prompt the user to enter an expected value you use InputBox.

It displays a prompt in a dialog box, waits for the user to enter value and finally returns a string containing the entry.

Except the prompt all other parameters are optional!

    Dim prompt As String = String.Empty
    Dim title As String = String.Empty
    Dim defaultResponse As String = String.Empty

    Dim answer As Object
    ' Set prompt.
    prompt = "Hello there. What's your name?"
    ' Set title.
    title = "Getting user input"
    ' Set default value.
    defaultResponse = "Your name here"

    ' Display prompt, title, and default value.
    answer = InputBox(prompt, title, defaultResponse)
    ' Say something to the user
    Messagebox.Show("Nice to meet you " & answer)

Previous Lesson | Next Lesson

Share This

Home | About | Contact | Privacy Policy

Copyright 2018 - All Rights Reserved.