#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default inputbox

Hi Im using
Dim appliances as integer
appsagain:

appliances = InputBox(Prompt:="Appliances.", _
Title:="Sheet" & a, Default:="0")
If appliances < 0 Then
MsgBox ("Number to small")
GoTo appsagain
ElseIf appliances 40 Then
MsgBox ("Number 40")
GoTo appsagain
End If
What I want to do is if text is used in the input box then restart. At
the momment if text is enetered then the code crashes. Any ideas.
Regards Robert
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default inputbox

Change appliances to a string, the input box returns the string, then test
by taking the Val(appliances)........ see below


Dim appliances As String
appsagain:

appliances = InputBox(Prompt:="Appliances.", _
Title:="Sheet" & a, Default:="0")
If Val(appliances) < 0 Then
MsgBox ("Number to small")
GoTo appsagain
ElseIf Val(appliances) 40 Then
MsgBox ("Number 40")
GoTo appsagain
End If

--

Regards,
Nigel




"RobcPettit" wrote in message
...
Hi Im using
Dim appliances as integer
appsagain:

appliances = InputBox(Prompt:="Appliances.", _
Title:="Sheet" & a, Default:="0")
If appliances < 0 Then
MsgBox ("Number to small")
GoTo appsagain
ElseIf appliances 40 Then
MsgBox ("Number 40")
GoTo appsagain
End If
What I want to do is if text is used in the input box then restart. At
the momment if text is enetered then the code crashes. Any ideas.
Regards Robert


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default inputbox

You can trap it within the inputbox itself. And you need to allow an escape
door.

As you are testing for <0, not <=0, I assume 0 is a valid value, so

Dim appliances As Variant
Dim AllDone As Boolean

Do
appliances = Application.InputBox( _
Prompt:="Appliances.", _
Title:="Sheet" & a, Default:="0", _
Type:=1)
If appliances = False Then
'cancel our
AllDone = True
ElseIf appliances < 0 Then
MsgBox "Number to small"
ElseIf appliances 40 Then
MsgBox "Number 40"
Else
AllDone = True
End If
Loop Until AllDone


--
__________________________________
HTH

Bob

"RobcPettit" wrote in message
...
Hi Im using
Dim appliances as integer
appsagain:

appliances = InputBox(Prompt:="Appliances.", _
Title:="Sheet" & a, Default:="0")
If appliances < 0 Then
MsgBox ("Number to small")
GoTo appsagain
ElseIf appliances 40 Then
MsgBox ("Number 40")
GoTo appsagain
End If
What I want to do is if text is used in the input box then restart. At
the momment if text is enetered then the code crashes. Any ideas.
Regards Robert



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default inputbox

You will do yourself the biggest favor programming-wise if you learn **not**
to rely on the GoTo statement for your program execution. Give this a try...

Do
Appliances = InputBox(Prompt:="Appliances.", _
Title:="Sheet" & A, Default:=0)
If Appliances Like String(Len(Appliances), "#") Then
If Appliances = "" Then
Appliances = 0
Exit Do
ElseIf Appliances < 0 Then
MsgBox "Negative numbers are not allowed!"
ElseIf Appliances 40 Then
MsgBox "Only numbers between 0 and 40 are allowed!"
Else
Exit Do
End If
Else
MsgBox "Your input was not an integer!"
End If
Loop

Note: If the user clicks Cancel, Appliances will be assigned the value 0.

Rick


"RobcPettit" wrote in message
...
Hi Im using
Dim appliances as integer
appsagain:

appliances = InputBox(Prompt:="Appliances.", _
Title:="Sheet" & a, Default:="0")
If appliances < 0 Then
MsgBox ("Number to small")
GoTo appsagain
ElseIf appliances 40 Then
MsgBox ("Number 40")
GoTo appsagain
End If
What I want to do is if text is used in the input box then restart. At
the momment if text is enetered then the code crashes. Any ideas.
Regards Robert


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
InputBox peyman Excel Discussion (Misc queries) 4 September 28th 07 04:53 PM
InputBox GeorgeJ Excel Discussion (Misc queries) 5 July 12th 07 01:20 AM
inputbox brownti via OfficeKB.com Excel Discussion (Misc queries) 2 February 9th 07 02:37 PM
Inputbox and Application.InputBox Maria[_7_] Excel Programming 1 September 20th 04 11:36 AM
Inputbox sadik Excel Programming 3 February 19th 04 07:14 PM


All times are GMT +1. The time now is 12:08 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"