if语句的奇怪行为 [英] Strange behaviour with if statement

查看:89
本文介绍了if语句的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

不确定之前是否有人经历过此事,并且可以告诉我这句话有什么错误:

如果已验证= false则dataObjects.HasError = true

这一切都在一行上,并且已验证定义为布尔变量。

无论验证是否设置为true或者总是执行错误

dataObjects.HasError = true。

以下代码按预期工作,dataObjects.HasError = true

仅在验证时执行设置为false。

如果验证= false则

dataObjects.HasError = true

结束如果

To最重要的是,我使用构造


如果[表达]然后[做某事]

在程序的其他地方,它工作正常。

有什么想法吗?

Thomas Born

解决方案

2004年9月8日20 :11:58-0700, tb***@hlra.com.au 写道:
< blockquote class =post_quotes>你好,
不确定是否有人之前曾经历过这个,并且可以告诉我这个陈述有什么错误:

如果验证了= false然后dataObjects.HasError = true

这一切都在一行上,并且验证被定义为布尔变量。
无论在ALWAYS执行中验证设置为true还是false
dataObjects.HasError = true。

以下代码按预期工作,dataObjects.HasError = true
仅在已验证设置为false时执行。

如果已验证= false然后
dataObjects.HasError = true
结束如果

最重要的是,我使用构造

if [expression] then [do一些东西]
在程序的其他地方,它工作正常。
任何想法?

Thomas Born




你确定它实际上正在执行吗?似乎有一个问题

与debuger和单行if语句...基本上,它出来了

的步骤,看起来它正在执行语句,但实际上,它不是b $ b。在步骤确认之前和之后检查值。


-

Tom Shelton [MVP]

是的,我自己在调试器中看到了这种确切的怪异。 (它没有b $ b b b执行它)。


我差点把头发拉出来试图调试这行代码:


尝试

...

最后

如果不是cn什么也不是,而且cn.State = ConnectionState.Open那么

cn.Close()

结束尝试


:^)


格雷格


汤姆谢尔顿 < to*@YOUKNOWTHEDRILLmtogden.com>在消息中写道

新闻:14 ***************************** @ 40tude.net ...

2004年9月8日20:11:58 -0700, tb *** @ hlra.com.au 写道:

你好,
不确定是否有人之前经历过这个,并且可以告诉我这句话的错误是什么:

如果已验证= false则dataObjects.HasError = true

这一切都在一行上,并且已验证定义为布尔变量。
无论是否已设置验证在ALWAYS中执行true或false执行
dataObjects.HasError = true。

以下代码按预期工作,dataObjects.HasError = true
仅在verify被设置为false时执行。 br />
如果验证= false那么
dataObjects.HasError = true
结束如果

最重要的是,我使用构造

if [表达]然后[做某事]
在程序的其他地方,它工作正常。
任何想法?

Thomas Born



你确定它实际上正在执行吗?似乎有一个问题
与debuger和单行if语句...基本上,它走出步骤,看起来它正在执行语句,但在实际上
它不是。在步骤确认之前和之后检查值。

- 汤姆谢尔顿[MVP]



2004年9月8日20:11:58 -0700, tb***@hlra.com.au 写道:

如果已验证= false则dataObjects.HasError = true



另一种编码此行的方法是避免使用if:


dataObjects.HasError =(未经过验证)


-

克里斯


dunawayc [AT] sbcglobal_lunchmeat_ [DOT] net


要给我发电子邮件,请删除[","],下划线,午餐肉和

替换我的电子邮件地址中的某些字词。


Hi there,
Not sure if any one has experienced this before and can tell me what''s
wrong with this statement:
if verified = false then dataObjects.HasError = true
This is all on one line and verified is defined as a boolean variable.
Irrespective if verified is set to true or false in ALWAYS executes
dataObjects.HasError = true.
Following code works as expected and dataObjects.HasError = true
executes only if verified is set to false.
if verified = false then
dataObjects.HasError = true
end if
To top it all of, I use the construct

if [expression] then [do something]
at other places in the program and it works fine.
Any ideas?
Thomas Born

解决方案

On 8 Sep 2004 20:11:58 -0700, tb***@hlra.com.au wrote:

Hi there,
Not sure if any one has experienced this before and can tell me what''s
wrong with this statement:
if verified = false then dataObjects.HasError = true
This is all on one line and verified is defined as a boolean variable.
Irrespective if verified is set to true or false in ALWAYS executes
dataObjects.HasError = true.
Following code works as expected and dataObjects.HasError = true
executes only if verified is set to false.
if verified = false then
dataObjects.HasError = true
end if
To top it all of, I use the construct

if [expression] then [do something]
at other places in the program and it works fine.
Any ideas?
Thomas Born



Are you sure that it is actually executing? It seems there was a problem
with the debuger and single line if statements... Basically, it gets out
of step and it looks like it is executing the statement, but in reallity
it''s not. Check the values, before and after you step to confirm.

--
Tom Shelton [MVP]


Yeah, I''ve see that exact weirdness in the debugger myself. (It doesn''t
actaully execute it).

I almost pulled my hair out trying to debug this line of code:

Try
...
Finally
If Not cn Is Nothing AndAlso cn.State = ConnectionState.Open Then
cn.Close()
End Try

:^)

Greg

"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:14*****************************@40tude.net...

On 8 Sep 2004 20:11:58 -0700, tb***@hlra.com.au wrote:

Hi there,
Not sure if any one has experienced this before and can tell me what''s
wrong with this statement:
if verified = false then dataObjects.HasError = true
This is all on one line and verified is defined as a boolean variable.
Irrespective if verified is set to true or false in ALWAYS executes
dataObjects.HasError = true.
Following code works as expected and dataObjects.HasError = true
executes only if verified is set to false.
if verified = false then
dataObjects.HasError = true
end if
To top it all of, I use the construct

if [expression] then [do something]
at other places in the program and it works fine.
Any ideas?
Thomas Born



Are you sure that it is actually executing? It seems there was a problem
with the debuger and single line if statements... Basically, it gets out
of step and it looks like it is executing the statement, but in reallity
it''s not. Check the values, before and after you step to confirm.

--
Tom Shelton [MVP]



On 8 Sep 2004 20:11:58 -0700, tb***@hlra.com.au wrote:

if verified = false then dataObjects.HasError = true


An alternate way to code this line would be to avoid the if altogether:

dataObjects.HasError = (Not verified)

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.


这篇关于if语句的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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