Results 1 to 14 of 14

Thread: very newbie InputBox question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Reynosa, Mexico
    Posts
    274
    When the string returned is ="", how can I know if user click on Cancel or let the text blank and click OK?
    Ulises Vázquez
    [size=1.7]Oracle DBA Certified Professioanl
    Visual Basic 6 Developer
    Crystal Reports Designer
    [/size]

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I'm not sure if you can tell, but why do you want to know that?

    If you really need it you could make your own inputbox, it's not that hard!

    If you give me one moment, maybe I'll find something for ya.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Guest
    It's easy.

    Code:
    iBox = Inputbox("Don't enter anything.")
    If iBox = "" Then
    Msgbox "Text was left blank or Cancel was pressed."
    Else
    End If
    [Edited by Matthew Gates on 09-07-2000 at 03:06 PM]

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    ghehe Matthew he wanted to know how you can tell the difference between Cancel and a blank Box
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Here's an idea: make the default value a single space, so that the box appears blank, and if the user wants to submit nothing then they press OK and you get " " returned. If they press cancel you get "" returned. It's a bit of a dodgy method, might be useful though.
    Harry.

    "From one thing, know ten thousand things."

  6. #6
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    the cancel proprity is
    vb2
    so :

    Dim Result1 As String
    try1:
    Result1 = inputbox("What is your name ?","","")
    If not Result1 = vb2 then
    If not Result1 = "" then
    'All is ok ..let's continue
    else
    a=msgbox ("you leave the box blank !",vbcritical,"ERROR")
    goto try1
    end if
    else
    end
    end if

  7. #7
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    The InputBox function returns the string the user entered, or a zero-length string if they pressed cancel. It doesn't return a value of type VbMsgBoxResult.
    Harry.

    "From one thing, know ten thousand things."

  8. #8
    Addicted Member
    Join Date
    Aug 2000
    Posts
    208
    I alway use this method and that's alway's work very good..
    an inputbox have the same result as a msgbox BUT dont contain any graphics ( I dont know how so ... ) .

  9. #9
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well you look in the help files then. The standard InputBox function returns a string. The VbMsgBoxResult type is just an Enum with values ranging from about 1 - 7, so if they enter a number in that range as a string and you compare it with a VbMsgBoxResult, the compiler will perform an implicit cast and compare the values. Possibly giving a weird result.

    The return value can't be a VbMsgBoxResult and a string.
    Harry.

    "From one thing, know ten thousand things."

  10. #10
    New Member
    Join Date
    Sep 2000
    Posts
    6

    Wink

    use that

    dim sStrin as string
    sString = InputBox("Your Text")

    if Trim(sString)="" then
    MsgBox "You enten nothing"
    endif


  11. #11
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Eortizr, please read the whole post, this is not what he want.
    I think the idea of HarryW is by far the best! smart thinking man

    Code:
    ibox = InputBox("Please enter something"," ")
    If ibox = " " Then
    'Ok was pressed and nothin' was filled in.
    ElseIf ibox = "" Then
    'Cancel was pressed
    End If
    All credits go to HarryW, I just made the example
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  12. #12
    Lively Member
    Join Date
    Apr 2000
    Posts
    110

    Coding Practice

    pro2, goto is shunned by most programmers. I would re-arrange that code you posted inside a 'do until' loop to keep popping the box up for input until the correct value is input.

    Later

    REM
    "Innovate, don't immitate."

  13. #13
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Yeah you're right REM, also pro2, never use end if it's not neccesary (< spellcheck?), instead, use
    Code:
    Unload <FORMNAME>
    'like:
    Unload Me
    'or
    Unload Form2
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  14. #14
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Talking try this

    aaron young gave me this one, a module he wrote to extend the input box. It includes a CancelError property, although I do not know how well that particular property works since i have yet to use it

    http://forums.vb-world.net/showthrea...threadid=19628

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