Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Exit Code Upon Cancel On Type 8 Input Box

For a custom dialogue box I was referred to the following excellent sample.
However, now that I have come across a situation in which a mistake took
place, upon pressing the "Cancel" button the rest of the code still seems to
be working!

How to exit the code if e.g. Cancel button of:
Application.InputBox(Prompt:="What is the price of house?", Type:=8)
is pressed?

Sub HCALC()
HouseCalc _
Application.InputBox(Prompt:="What is the price of house?", Type:=8), _
Application.InputBox(Prompt:="What is your earning?", Type:=8)
End Sub
===
Sub HouseCalc(price As Double, wage As Double)
If wage < price Then
MsgBox "With an excess of " & price - wage & " in the price you
cannot afford this house.", , "SORRY!!!"
Else
MsgBox "With an excess earnings of " & wage - price & " this house
is affordable.", , "YAHOO!!!"
End If
MsgBox "Your Earning Is " & wage & "!" & vbNewLine & "Whereas The
House Costs " & price & "!", , "RESULT!!!"
End Sub


--

Best Regards,
FARAZ A. QURESHI
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Exit Code Upon Cancel On Type 8 Input Box

Sub HCALC()
Dim price As Range
Dim earn As Range
On Error Resume Next
Set price = Application.InputBox(Prompt:="What is the price of house?",
Type:=8)
If Not price Is Nothing Then
Set earn = Application.InputBox(Prompt:="What is your earning?",
Type:=8)
If Not earn Is Nothing Then
On Error GoTo 0
HouseCalc price.Value, earn.Value
End If
End If
End Sub

Sub HouseCalc(price As Double, wage As Double)
If wage < price Then
MsgBox "With an excess of " & price - wage & " in the price " & _
"you cannot afford this house.", , "SORRY!!!"
Else
MsgBox "With an excess earnings of " & wage - price & " this house "
& _
"is affordable.", , "YAHOO!!!"
End If
MsgBox "Your Earning Is " & wage & "!" & vbNewLine & "Whereas The "
& _
"House Costs " & price & "!", , "RESULT!!!"
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"FARAZ QURESHI" wrote in message
...
For a custom dialogue box I was referred to the following excellent
sample.
However, now that I have come across a situation in which a mistake took
place, upon pressing the "Cancel" button the rest of the code still seems
to
be working!

How to exit the code if e.g. Cancel button of:
Application.InputBox(Prompt:="What is the price of house?", Type:=8)
is pressed?

Sub HCALC()
HouseCalc _
Application.InputBox(Prompt:="What is the price of house?", Type:=8), _
Application.InputBox(Prompt:="What is your earning?", Type:=8)
End Sub
===
Sub HouseCalc(price As Double, wage As Double)
If wage < price Then
MsgBox "With an excess of " & price - wage & " in the price you
cannot afford this house.", , "SORRY!!!"
Else
MsgBox "With an excess earnings of " & wage - price & " this house
is affordable.", , "YAHOO!!!"
End If
MsgBox "Your Earning Is " & wage & "!" & vbNewLine & "Whereas The
House Costs " & price & "!", , "RESULT!!!"
End Sub


--

Best Regards,
FARAZ A. QURESHI



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Exit Code Upon Cancel On Type 8 Input Box

You could re-write the input module or di this

Sub HouseCalc(price As Double, wage As Double)
If wage = 0 Or price = 0 Then Exit Sub


Mike

"FARAZ QURESHI" wrote:

For a custom dialogue box I was referred to the following excellent sample.
However, now that I have come across a situation in which a mistake took
place, upon pressing the "Cancel" button the rest of the code still seems to
be working!

How to exit the code if e.g. Cancel button of:
Application.InputBox(Prompt:="What is the price of house?", Type:=8)
is pressed?

Sub HCALC()
HouseCalc _
Application.InputBox(Prompt:="What is the price of house?", Type:=8), _
Application.InputBox(Prompt:="What is your earning?", Type:=8)
End Sub
===
Sub HouseCalc(price As Double, wage As Double)
If wage < price Then
MsgBox "With an excess of " & price - wage & " in the price you
cannot afford this house.", , "SORRY!!!"
Else
MsgBox "With an excess earnings of " & wage - price & " this house
is affordable.", , "YAHOO!!!"
End If
MsgBox "Your Earning Is " & wage & "!" & vbNewLine & "Whereas The
House Costs " & price & "!", , "RESULT!!!"
End Sub


--

Best Regards,
FARAZ A. QURESHI

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify the code for different type of input? Eric Excel Worksheet Functions 1 September 1st 07 03:58 PM
How to modify the code for different type of input? Eric Excel Discussion (Misc queries) 2 September 1st 07 12:30 AM
InputBox / VBA question ok = print, cancel = exit todd78 Excel Worksheet Functions 4 August 9th 07 04:42 PM
Input Box - CANCEL Danny Excel Worksheet Functions 6 December 1st 06 02:15 AM
cancel input ME @ Home Excel Discussion (Misc queries) 1 February 22nd 06 09:49 AM


All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"