I want to track the button clicks in my inputbox function. I want to perform one action when I press OK and I want to perform another when I press Cancel button. Is there any way to do it?
Printable View
I want to track the button clicks in my inputbox function. I want to perform one action when I press OK and I want to perform another when I press Cancel button. Is there any way to do it?
the one way is inputbox returns value typed in text box in as a string when u press ok and blank strin when u press cancel....so u can check
temp=inputbox("Enter ur Name")
if not temp="" then
msgbox "OK"
else
msgbox "Cancel"
end if
VB Code:
Private Sub Form_Load() Dim s As String s = InputBox("Give!") If StrPtr(s) = 0 Then MsgBox "Cancel was pressed" Else MsgBox "Ok was pressed" End If End Sub
Greetings, bug boy.
If the user presses OK without typing anything, u still get "" .... ?Quote:
Originally posted by Dinz
the one way is inputbox returns value typed in text box in as a string when u press ok and blank strin when u press cancel....so u can check
temp=inputbox("Enter ur Name")
if not temp="" then
msgbox "OK"
else
msgbox "Cancel"
end if
hey FoxyFrog !Quote:
Originally posted by mendhak
Greetings, bug boy.
What's strptr() ?
my english is no good, so I'll leave the explanation to MSN ;)Quote:
MSN
Strings in Visual Basic are stored as BSTR's. If you use the VarPtr on a variable of type String, you will get the address of the BSTR, which is a pointer to a pointer of the string. To get the address of the string buffer itself, you need to use the StrPtr function. This function returns the address of the first character of the string. Take into account that Strings are stored as UNICODE in Visual Basic.
To get the address of the first character of a String, pass the String variable to the StrPtr function.
Example:
Dim lngCharAddress as Long
Dim strMyVariable as String
strMyVariable = "Some String"
lngCharAddress = StrPtr(strMyVariable)
This is why my sample will work. If Ok is pressed without the user adding any data to the input field, StrPtr will still return a value, because the variable has been assigned the "" value, wheras if the user click cancel, the StrPtr will return 0
:)
I semiunderstood that. So a half hearted thank you. :)
wow...this was an amazing information......hats off peet