CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Input box

  1. #1
    Join Date
    Jul 2001
    Posts
    28

    Input box

    I am using input box in my application. The input box returns the string value entered in the text box. How can i
    know whether user has pressed 'OK' button or 'Cancel' button in input box.

    Chandar


  2. #2
    Join Date
    Jul 2001
    Posts
    28

    Re: Input box

    I got the answer Read on

    if the user presses cancel, vbNullString is returned. However if they press OK, the empty string ("") is sent back.
    But in Visual Basic, vbNullString equates to an empty string, so you can't compare the two - even though in reality, they're
    completely different.

    However you can use the StrPtr ('string pointer') function to determine whether the return string is indeed a vbNullString -
    as by definition, a vbNullString 'pointer' is zero.

    And this code demonstrates how to do that.

    Code

    Dim strInput As String

    strInput = InputBox("Enter something:")

    If StrPtr(strInput) = 0 Then
    MsgBox "You pressed cancel!"
    End If


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured