判断X是否介于两个值之间的最佳方法是什么? A97 [英] Best way to tell if X is between two values? A97

查看:92
本文介绍了判断X是否介于两个值之间的最佳方法是什么? A97的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

225如果1< = MyCount< = 4那么GString =几天前。

230如果5< = MyCount< = 10那么GString =大约一周前。

235如果11< = MyCount< = 17那么GString ="大约2周前。

240如果18< = MyCount< = 24则GString ="约3周前。

245如果25< = MyCount< = 30那么GString =约一个月前。


以上几行不符合我的预期。什么是最好的方式

来做我想做的事情。如果你对上面的语法感到困惑,那么
那就不要打扰 - 它的旧东西。

解决方案

225如果1< = MyCount和MyCount< = 4那么GString =blan

230如果5< = MyCount和MyCount< = 10那么GString =" blah"

235如果11< = MyCount和MyCount< = 17那么GString =" blah"

240如果18< = MyCount和MyCount< = 24那么GString =" blah"


我知道上面的语法,好的。我只是想知道是否有另外一种类似于OP中旧式速记方式的方式?


可能有点长时间啰嗦输入所有案例但是 -


选择案例MyCount

案例

.....

结束选择


或者可能与之间的运营商


Select Case MyCount

Case MyCount介于1和之间4

GString =几天前 

Case MyCount介于5和10之间
GString =大约一周前"

.....

结束选择

-

Nick Coe(英国)
http://www.alphacos.co.uk/ AccHelp + pAnimal
http://www.pjandcoe.co.uk/ 在线商店
http://www.mrcomputersltd.com/ 代表airs upgrades


新闻:09 ******************************** @ 4ax.com,

MLH键入:

225如果1< = MyCount< = 4那么GString =几天之前。
230如果5< = MyCount< = 10那么GString =一周左右
之前。 " 235如果11< = MyCount< = 17那么GString =
约2周前。 " 240如果18< = MyCount< = 24则GString =
"约3周前。 " 245如果25< = MyCount< = 30那么
GString ="大约一个月前。

以上几行不符合我的预期。做我想做的事最好的方法是什么?如果您对上面的
语法感到困惑,那就不要打扰了 - 它的旧东西。





" Nick Coe(英国)" < CL ***************** @ MASPON.yahooDOTcom>在消息中写道

news:43 ********************** @ ptn-nntp-reader02.plus.net ... < blockquote class =post_quotes>可能有点长啰嗦要输入所有的情况但是 -

选择Case MyCount
案例
....
结束选择

或者可能与之间的运营商

选择案例MyCount
案例MyCount介于1和4之间
GString =几天前" <案例MyCount介于5和10之间
GString =大约一周前
....
结束选择

-
Nick Coe(英国)




Select Case是理想的解决方案,但使用To操作符。


选择Case MyCount

案例1至4:GS ....

案例5至10:GS ......



结束选择


选择Case优于原始发布代码的一个原因是效率。

它只会评估直到找到匹配项然后退出案例陈述。

使用之前发布的代码,IF ... Then语句系列,即使第一个命中,也会对其进行评估。


兰迪


225 If 1 <= MyCount <= 4 Then GString = "a few days ago. "
230 If 5 <= MyCount <= 10 Then GString = "a week or so ago. "
235 If 11 <= MyCount <= 17 Then GString = "about 2 weeks ago. "
240 If 18 <= MyCount <= 24 Then GString = "about 3 weeks ago. "
245 If 25 <= MyCount <= 30 Then GString = "about a month ago. "

The above lines do not do what I expected. What''s the best way
to do what I''m trying to do. If you''re confused by the above syntax,
then don''t bother - its old stuff.

解决方案

225 If 1 <= MyCount And MyCount <= 4 Then GString = "blan"
230 If 5 <= MyCount And MyCount <= 10 Then GString = "blah "
235 If 11 <= MyCount And MyCount <= 17 Then GString = "blah"
240 If 18 <= MyCount And MyCount <= 24 Then GString = "blah"

I know about the above syntax, OK. I just wondered if there was
another way similar to the old-style shorthand approach in the OP?


Might be a bit long winded to type in all the cases but -

Select Case MyCount
Case
.....
End Select

or perhaps with the between operator

Select Case MyCount
Case MyCount Between 1 and 4
GString = "a few days ago"
Case MyCount Between 5 And 10
GString = "a week or so ago"
.....
End Select
--
Nick Coe (UK)
http://www.alphacos.co.uk/ AccHelp + pAnimal
http://www.pjandcoe.co.uk/ Online Store
http://www.mrcomputersltd.com/ Repairs Upgrades

In news:09********************************@4ax.com,
MLH typed:

225 If 1 <= MyCount <= 4 Then GString = "a few days
ago. "
230 If 5 <= MyCount <= 10 Then GString = "a week or so
ago. " 235 If 11 <= MyCount <= 17 Then GString =
"about 2
weeks ago. " 240 If 18 <= MyCount <= 24 Then GString =
"about 3 weeks ago. " 245 If 25 <= MyCount <= 30 Then
GString = "about a month ago. "

The above lines do not do what I expected. What''s the best
way
to do what I''m trying to do. If you''re confused by the
above
syntax, then don''t bother - its old stuff.




"Nick Coe (UK)" <cl*****************@MASPON.yahooDOTcom> wrote in message
news:43**********************@ptn-nntp-reader02.plus.net...

Might be a bit long winded to type in all the cases but -

Select Case MyCount
Case
....
End Select

or perhaps with the between operator

Select Case MyCount
Case MyCount Between 1 and 4
GString = "a few days ago"
Case MyCount Between 5 And 10
GString = "a week or so ago"
....
End Select
--
Nick Coe (UK)



Select Case is the ideal solution for this, but use the To operator.

Select Case MyCount
Case 1 To 4 : GS....
Case 5 To 10: GS...
etc
End Select

One reason for choosing Case over the original posted code is efficiency.
It will only evaluate until a match is found then exit the Case statement.
With the earlier posted code, the series of IF...Then statements, all would
get evaluated, even if the first one hit.

Randy


这篇关于判断X是否介于两个值之间的最佳方法是什么? A97的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆