Using InputBox Cancel Option

JOSHSKORN
12-07-2004, 12:29 PM
I have code similar to this:

pstrWord=InputBox("Please enter a word","Word Prompt")

I want to either enter in a word and click OK, or enter in nothing and click on CANCEL and produce the following message.

MessageBox.Show("This process has been cancelled.","Notice")

Clicking on Cancel seems to do the same thing as clicking on OK. Please help.

theplustwo
12-07-2004, 12:57 PM
A simple solution would be to do something like this:

If (pstrWord = Nothing) Then
MessageBox.Show("This process has been cancelled.", "Notice")
End If

Of course then the message box will show even if the user clicks OK with no input.

JOSHSKORN
12-07-2004, 01:16 PM
A simple solution would be to do something like this:

If (pstrWord = Nothing) Then
MessageBox.Show("This process has been cancelled.", "Notice")
End If

Of course then the message box will show even if the user clicks OK with no input.

This solution is perfect! Thank you. Here's my updated code for anyone curious:


Sub Main()
Dim pstrPassword As String

pstrPassword = InputBox("Enter password to start Program.", "Password Required")
If UCase(pstrPassword) = "LAB" Then
MessageBox.Show("Correct Password.", "Notice")
Exit Sub
ElseIf pstrPassword = Nothing Then
MessageBox.Show("You have cancelled this action.", "Notice")
Else
MessageBox.Show("You have entered an invalid password! This application will not launch.", "Password Error", MessageBoxButtons.OK, MessageBoxIcon.Hand)
End If
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum