Inputbox - cancel button -vb.net
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Inputbox - cancel button -vb.net

  1. #1
    Join Date
    Jul 2005
    Posts
    7

    Inputbox - cancel button -vb.net

    Hi,

    I am using InputBox to enter Text in VB.net.

    When user click OK button - enter nothing need to get message "Empty text. Please Enter the text"
    when Cancel button is clicked - need to close the Form window.

    I am having problem in finding which button is clicked. Can anyone help me with this please.
    or please let me know if there is any other way do this.

    Thank you.

  2. #2
    Join Date
    Jun 2005
    Posts
    34

    Re: Inputbox - cancel button -vb.net

    Unfortunately VB returns a zero-length string if cancel is pressed. So hitting enter/Okay without entering anything is the same as hitting cancel to VB.

    MyInput = InputBox("Enter text", "Entering Text","Text to enter")

    If MyInput = "" Then
    Me.Close()
    Else
    'Do something with the input
    End If

    That's the only way I can see you doing anything with this.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,098

    Re: Inputbox - cancel button -vb.net


  4. #4
    Join Date
    Jul 2005
    Posts
    7

    Re: Inputbox - cancel button -vb.net

    Thankyou.

  5. #5
    Join Date
    Aug 2008
    Posts
    1

    Re: Inputbox - cancel button -vb.net

    You can just set the default value to a space then trim it off when you read the value.

    Code:
    /* use VB.Net function to prompt the user for a password. */
                string Prompt = "A password is required.";
                string Title = "Title";
                string Result = Microsoft.VisualBasic.Interaction.InputBox(Prompt, Title, " ", 150, 150);
    
                /* Build the password. */
    
                password = "meh";
                
    /* check to see it it's an empty string indicating they canceled. */
                if (Result != "")
                {
                    Result = Result.TrimStart();
                    /* Check to make sure the password matches. */
                    if (Result != password)
                    {
                        MessageBox.Show("Incorrect password.");
                    }
                    else
                    {
                        MessageBox.Show("correct password.");
                    }
                }
    Last edited by HanneSThEGreaT; August 15th, 2008 at 01:51 AM. Reason: Added [CODE] [/CODE] Tags!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center