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:
gt;
gt; Howdy,
gt;
gt; Can someone tell me why this loop accepts any value rather than the set
gt; constants?
gt;
gt; Dim shp as Long
gt; Dim shpSw as Integer
gt;
gt; Do while shpSw = 0
gt;
gt; shp = inputbox(quot;Please enter a number:quot;)
gt;
gt; if shp = 1 or 2 or 3 or 4 then
gt; shpSw =1
gt;
gt; else
gt;
gt; Msgbox(quot;Please enter a number from 1-4quot;)
gt;
gt; end if
gt; Loop
gt;
gt; Should be a simple loop that if say quot;5quot; is entered will give the msgbox
gt; and loop but it is accepting 5 and setting my switch to 1.
gt;
gt; Thanks for the help in advance,
gt;
gt; Mjack
gt;
gt; --
gt; mjack003
gt; ------------------------------------------------------------------------
gt; mjack003's Profile: www.excelforum.com/member.php...foamp;userid=5141
gt; View this thread: www.excelforum.com/showthread...hreadid=494023
--
Dave Peterson
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(quot;Please enter a number:quot;)
if shp = 1 or 2 or 3 or 4 then
shpSw =1
else
Msgbox(quot;Please enter a number from 1-4quot;)
end if
LoopShould be a simple loop that if say quot;5quot; 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: www.excelforum.com/member.php...foamp;userid=5141
View this thread: www.excelforum.com/showthread...hreadid=494023I 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(quot;Please enter a number from 1-4quot;)
End SelectDave Peterson wrote:
gt; I'd guess it was this line:
gt;
gt; if shp = 1 or 2 or 3 or 4 then
gt;
gt; I think you want:
gt;
gt; if shp = 1 _
gt; or shp = 2 _
gt; or shp = 3 _
gt; or shp = 4 then
gt;
gt;
gt;
gt; mjack003 wrote:
gt; gt;
gt; gt; Howdy,
gt; gt;
gt; gt; Can someone tell me why this loop accepts any value rather than the set
gt; gt; constants?
gt; gt;
gt; gt; Dim shp as Long
gt; gt; Dim shpSw as Integer
gt; gt;
gt; gt; Do while shpSw = 0
gt; gt;
gt; gt; shp = inputbox(quot;Please enter a number:quot;)
gt; gt;
gt; gt; if shp = 1 or 2 or 3 or 4 then
gt; gt; shpSw =1
gt; gt;
gt; gt; else
gt; gt;
gt; gt; Msgbox(quot;Please enter a number from 1-4quot;)
gt; gt;
gt; gt; end if
gt; gt; Loop
gt; gt;
gt; gt; Should be a simple loop that if say quot;5quot; is entered will give the msgbox
gt; gt; and loop but it is accepting 5 and setting my switch to 1.
gt; gt;
gt; gt; Thanks for the help in advance,
gt; gt;
gt; gt; Mjack
gt; gt;
gt; gt; --
gt; gt; mjack003
gt; gt; ------------------------------------------------------------------------
gt; gt; mjack003's Profile: www.excelforum.com/member.php...foamp;userid=5141
gt; gt; View this thread: www.excelforum.com/showthread...hreadid=494023
gt;
gt; --
gt;
gt; Dave PetersonExcellent tip.
But I did want to show the OP why his (her?) if statement was incorrect.
Andrew Taylor wrote:
gt;
gt; I think there's a good case (haha) for using Select Case
gt; in this sort of situation:
gt;
gt; Select Case shp
gt; Case 1, 2, 3, 4
gt; shpSw =1
gt; Case Else
gt; Msgbox(quot;Please enter a number from 1-4quot;)
gt; End Select
gt;
gt; Dave Peterson wrote:
gt; gt; I'd guess it was this line:
gt; gt;
gt; gt; if shp = 1 or 2 or 3 or 4 then
gt; gt;
gt; gt; I think you want:
gt; gt;
gt; gt; if shp = 1 _
gt; gt; or shp = 2 _
gt; gt; or shp = 3 _
gt; gt; or shp = 4 then
gt; gt;
gt; gt;
gt; gt;
gt; gt; mjack003 wrote:
gt; gt; gt;
gt; gt; gt; Howdy,
gt; gt; gt;
gt; gt; gt; Can someone tell me why this loop accepts any value rather than the set
gt; gt; gt; constants?
gt; gt; gt;
gt; gt; gt; Dim shp as Long
gt; gt; gt; Dim shpSw as Integer
gt; gt; gt;
gt; gt; gt; Do while shpSw = 0
gt; gt; gt;
gt; gt; gt; shp = inputbox(quot;Please enter a number:quot;)
gt; gt; gt;
gt; gt; gt; if shp = 1 or 2 or 3 or 4 then
gt; gt; gt; shpSw =1
gt; gt; gt;
gt; gt; gt; else
gt; gt; gt;
gt; gt; gt; Msgbox(quot;Please enter a number from 1-4quot;)
gt; gt; gt;
gt; gt; gt; end if
gt; gt; gt; Loop
gt; gt; gt;
gt; gt; gt; Should be a simple loop that if say quot;5quot; is entered will give the msgbox
gt; gt; gt; and loop but it is accepting 5 and setting my switch to 1.
gt; gt; gt;
gt; gt; gt; Thanks for the help in advance,
gt; gt; gt;
gt; gt; gt; Mjack
gt; gt; gt;
gt; gt; gt; --
gt; gt; gt; mjack003
gt; gt; gt; ------------------------------------------------------------------------
gt; gt; gt; mjack003's Profile: www.excelforum.com/member.php...foamp;userid=5141
gt; gt; gt; View this thread: www.excelforum.com/showthread...hreadid=494023
gt; gt;
gt; gt; --
gt; gt;
gt; gt; Dave Peterson
--
Dave Peterson
lt;OTgt;
Dredging the recesses of my memory, the quot;1 or 2 or 3 or 4quot; 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..
lt;/OTgt;Dave Peterson wrote:
gt; Excellent tip.
gt;
gt; But I did want to show the OP why his (her?) if statement was incorrect.
gt;
gt; Andrew Taylor wrote:
gt; gt;
gt; gt; I think there's a good case (haha) for using Select Case
gt; gt; in this sort of situation:
gt; gt;
gt; gt; Select Case shp
gt; gt; Case 1, 2, 3, 4
gt; gt; shpSw =1
gt; gt; Case Else
gt; gt; Msgbox(quot;Please enter a number from 1-4quot;)
gt; gt; End Select
gt; gt;
gt; gt; Dave Peterson wrote:
gt; gt; gt; I'd guess it was this line:
gt; gt; gt;
gt; gt; gt; if shp = 1 or 2 or 3 or 4 then
gt; gt; gt;
gt; gt; gt; I think you want:
gt; gt; gt;
gt; gt; gt; if shp = 1 _
gt; gt; gt; or shp = 2 _
gt; gt; gt; or shp = 3 _
gt; gt; gt; or shp = 4 then
gt; gt; gt;
gt; gt; gt;
gt; gt; gt;
gt; gt; gt; mjack003 wrote:
gt; gt; gt; gt;
gt; gt; gt; gt; Howdy,
gt; gt; gt; gt;
gt; gt; gt; gt; Can someone tell me why this loop accepts any value rather than the set
gt; gt; gt; gt; constants?
gt; gt; gt; gt;
gt; gt; gt; gt; Dim shp as Long
gt; gt; gt; gt; Dim shpSw as Integer
gt; gt; gt; gt;
gt; gt; gt; gt; Do while shpSw = 0
gt; gt; gt; gt;
gt; gt; gt; gt; shp = inputbox(quot;Please enter a number:quot;)
gt; gt; gt; gt;
gt; gt; gt; gt; if shp = 1 or 2 or 3 or 4 then
gt; gt; gt; gt; shpSw =1
gt; gt; gt; gt;
gt; gt; gt; gt; else
gt; gt; gt; gt;
gt; gt; gt; gt; Msgbox(quot;Please enter a number from 1-4quot;)
gt; gt; gt; gt;
gt; gt; gt; gt; end if
gt; gt; gt; gt; Loop
gt; gt; gt; gt;
gt; gt; gt; gt; Should be a simple loop that if say quot;5quot; is entered will give the msgbox
gt; gt; gt; gt; and loop but it is accepting 5 and setting my switch to 1.
gt; gt; gt; gt;
gt; gt; gt; gt; Thanks for the help in advance,
gt; gt; gt; gt;
gt; gt; gt; gt; Mjack
gt; gt; gt; gt;
gt; gt; gt; gt; --
gt; gt; gt; gt; mjack003
gt; gt; gt; gt; ------------------------------------------------------------------------
gt; gt; gt; gt; mjack003's Profile: www.excelforum.com/member.php...foamp;userid=5141
gt; gt; gt; gt; View this thread: www.excelforum.com/showthread...hreadid=494023
gt; gt; gt;
gt; gt; gt; --
gt; gt; gt;
gt; gt; gt; Dave Peterson
gt;
gt; --
gt;
gt; Dave Peterson
- Jul 16 Mon 2007 20:38
Loop gone crazy
close
全站熱搜
留言列表
發表留言