#1   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Loop gone crazy

I'd guess it was this line:

if shp = 1 or 2 or 3 or 4 then

I think you want:

if shp = 1 _
or shp = 2 _
or shp = 3 _
or shp = 4 then



mjack003 wrote:

Howdy,

Can someone tell me why this loop accepts any value rather than the set
constants?

Dim shp as Long
Dim shpSw as Integer

Do while shpSw = 0

shp = inputbox("Please enter a number:")

if shp = 1 or 2 or 3 or 4 then
shpSw =1

else

Msgbox("Please enter a number from 1-4")

end if
Loop

Should be a simple loop that if say "5" is entered will give the msgbox
and loop but it is accepting 5 and setting my switch to 1.

Thanks for the help in advance,

Mjack

--
mjack003
------------------------------------------------------------------------
mjack003's Profile: http://www.excelforum.com/member.php...fo&userid=5141
View this thread: http://www.excelforum.com/showthread...hreadid=494023


--

Dave Peterson
  #2   Report Post  
Posted to microsoft.public.excel.misc
mjack003
 
Posts: n/a
Default Loop gone crazy


Howdy,

Can someone tell me why this loop accepts any value rather than the set
constants?

Dim shp as Long
Dim shpSw as Integer

Do while shpSw = 0

shp = inputbox("Please enter a number:")

if shp = 1 or 2 or 3 or 4 then
shpSw =1

else

Msgbox("Please enter a number from 1-4")

end if
Loop


Should be a simple loop that if say "5" is entered will give the msgbox
and loop but it is accepting 5 and setting my switch to 1.

Thanks for the help in advance,

Mjack


--
mjack003
------------------------------------------------------------------------
mjack003's Profile: http://www.excelforum.com/member.php...fo&userid=5141
View this thread: http://www.excelforum.com/showthread...hreadid=494023

  #3   Report Post  
Posted to microsoft.public.excel.misc
Andrew Taylor
 
Posts: n/a
Default Loop gone crazy

I think there's a good case (haha) for using Select Case
in this sort of situation:

Select Case shp
Case 1, 2, 3, 4
shpSw =1
Case Else
Msgbox("Please enter a number from 1-4")
End Select


Dave Peterson wrote:
I'd guess it was this line:

if shp = 1 or 2 or 3 or 4 then

I think you want:

if shp = 1 _
or shp = 2 _
or shp = 3 _
or shp = 4 then



mjack003 wrote:

Howdy,

Can someone tell me why this loop accepts any value rather than the set
constants?

Dim shp as Long
Dim shpSw as Integer

Do while shpSw = 0

shp = inputbox("Please enter a number:")

if shp = 1 or 2 or 3 or 4 then
shpSw =1

else

Msgbox("Please enter a number from 1-4")

end if
Loop

Should be a simple loop that if say "5" is entered will give the msgbox
and loop but it is accepting 5 and setting my switch to 1.

Thanks for the help in advance,

Mjack

--
mjack003
------------------------------------------------------------------------
mjack003's Profile: http://www.excelforum.com/member.php...fo&userid=5141
View this thread: http://www.excelforum.com/showthread...hreadid=494023


--

Dave Peterson


  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Loop gone crazy

Excellent tip.

But I did want to show the OP why his (her?) if statement was incorrect.

Andrew Taylor wrote:

I think there's a good case (haha) for using Select Case
in this sort of situation:

Select Case shp
Case 1, 2, 3, 4
shpSw =1
Case Else
Msgbox("Please enter a number from 1-4")
End Select

Dave Peterson wrote:
I'd guess it was this line:

if shp = 1 or 2 or 3 or 4 then

I think you want:

if shp = 1 _
or shp = 2 _
or shp = 3 _
or shp = 4 then



mjack003 wrote:

Howdy,

Can someone tell me why this loop accepts any value rather than the set
constants?

Dim shp as Long
Dim shpSw as Integer

Do while shpSw = 0

shp = inputbox("Please enter a number:")

if shp = 1 or 2 or 3 or 4 then
shpSw =1

else

Msgbox("Please enter a number from 1-4")

end if
Loop

Should be a simple loop that if say "5" is entered will give the msgbox
and loop but it is accepting 5 and setting my switch to 1.

Thanks for the help in advance,

Mjack

--
mjack003
------------------------------------------------------------------------
mjack003's Profile: http://www.excelforum.com/member.php...fo&userid=5141
View this thread: http://www.excelforum.com/showthread...hreadid=494023


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
Andrew Taylor
 
Posts: n/a
Default Loop gone crazy

<OT
Dredging the recesses of my memory, the "1 or 2 or 3 or 4" idiom
used to be (probably still is for all I know...) valid in COBOL:

IF THING = 1 OR 2 OR 3 OR 4....

as an abbreviation for IF THING = 1 OR THING = 2 OR ....

You could even put NOTs in there, which was guaranteed to
catch the unwary, who would write:

IF THING NOT = 1 OR 2...

which unfortunately means IF THING NOT = 1 OR THING NOT = 2..
</OT


Dave Peterson wrote:
Excellent tip.

But I did want to show the OP why his (her?) if statement was incorrect.

Andrew Taylor wrote:

I think there's a good case (haha) for using Select Case
in this sort of situation:

Select Case shp
Case 1, 2, 3, 4
shpSw =1
Case Else
Msgbox("Please enter a number from 1-4")
End Select

Dave Peterson wrote:
I'd guess it was this line:

if shp = 1 or 2 or 3 or 4 then

I think you want:

if shp = 1 _
or shp = 2 _
or shp = 3 _
or shp = 4 then



mjack003 wrote:

Howdy,

Can someone tell me why this loop accepts any value rather than the set
constants?

Dim shp as Long
Dim shpSw as Integer

Do while shpSw = 0

shp = inputbox("Please enter a number:")

if shp = 1 or 2 or 3 or 4 then
shpSw =1

else

Msgbox("Please enter a number from 1-4")

end if
Loop

Should be a simple loop that if say "5" is entered will give the msgbox
and loop but it is accepting 5 and setting my switch to 1.

Thanks for the help in advance,

Mjack

--
mjack003
------------------------------------------------------------------------
mjack003's Profile: http://www.excelforum.com/member.php...fo&userid=5141
View this thread: http://www.excelforum.com/showthread...hreadid=494023

--

Dave Peterson


--

Dave Peterson


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
Do Loop Noemi Excel Discussion (Misc queries) 0 December 8th 05 10:43 PM
Help with Do...Loop Noemi Excel Discussion (Misc queries) 1 December 7th 05 12:59 AM
hysteresis loop olivekim Charts and Charting in Excel 1 October 28th 05 04:22 AM
VB for excel, how do I loop through code steve hobden via OfficeKB.com Excel Discussion (Misc queries) 2 June 9th 05 01:59 PM
loop trough e-mail address list to send task lists with outlook Paul. Excel Discussion (Misc queries) 2 April 14th 05 11:48 AM


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