When the string returned is ="", how can I know if user click on Cancel or let the text blank and click OK?
Printable View
When the string returned is ="", how can I know if user click on Cancel or let the text blank and click OK?
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.
It's easy.
[Edited by Matthew Gates on 09-07-2000 at 03:06 PM]Code:iBox = Inputbox("Don't enter anything.")
If iBox = "" Then
Msgbox "Text was left blank or Cancel was pressed."
Else
End If
ghehe Matthew :) he wanted to know how you can tell the difference between Cancel and a blank Box
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.
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
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.
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 ... ) .
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.
use that
dim sStrin as string
sString = InputBox("Your Text")
if Trim(sString)="" then
MsgBox "You enten nothing"
endif
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 :)
All credits go to HarryW, I just made the example :)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
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
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
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