473,698 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange behaviour with if statement

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.Has Error = 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.Has Error = true.
Following code works as expected and dataObjects.Has Error = true
executes only if verified is set to false.
if verified = false then
dataObjects.Has Error = 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

Nov 21 '05
10 1196
Cor,

I was going to write back and say that the Finally block had nothing to do
with it. (Just happened to be in my example). But when I tried it without
the Finally, it doesn't do it! It is CRAZY! :^)

Greg

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:uf******** *****@tk2msftng p13.phx.gbl...
Greg,

It was exactly as you said yesterday what you said and thought that I got
not that behaviour, tomorrow I get it, with this as well,
\\\
Try
Catch ex As Exception
Finally
If 0 = 1 Then MessageBox.Show ("hello")
End Try
///
And only in the Finnally block, and it will not be exectuted, it shows it
is
executed.

In your example it can be the right situation when this error on the open.
However in this case, when I set it in a three line If statement, it
behaves
in another way as you said, crazy.

Cor

I just tried you exact code and it behaves the same whether I disable the
first close or not.

Understand, nobody is disputing that if the connection is already closed

it
will NOT try and close it again. The code works properly.

It is simpy this; if you step through with the debugger it ALWAYS

highlights
that cn.Close on the other side of the Then. It appears that it is
exectuing it, whether it is or not.

Make sense? I added a screen shot (and simplified the If expression)

Greg

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:OW******** ******@TK2MSFTN GP12.phx.gbl...
> Greg,
>
> I changed it to this,
>
> \\\
> Dim cn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;Data > Source=C:\whate ver.mdb")
> cn.Open()
> cn.Close()
> Try
> Catch ex As Exception
> Finally
> If Not cn Is Nothing AndAlso cn.State = ConnectionState .Open
> Then cn.Close()
> End Try
> ///
> I have a different behaviour when I disable that first close.
>
> Cor
>
>> No, you got to do my example. The problem is when If Then is one
>> line,
>> no
>> End If.
>>
>> You won't be able to throw in a messagebox like you are trying. You will >> have to step through with the debugger.
>>
>> If Not cn Is Nothing AndAlso cn.State = ConnectionState .Open Then
> cn.Close()
>> <-- all one line
>>
>>
>> Greg
>>
>>
>> "Cor Ligthert" <no**********@p lanet.nl> wrote in message
>> news:Ol******** ******@TK2MSFTN GP12.phx.gbl...
>> > Greg
>> > I tried this and no strange results
>> >
>> > \\\
>> > Dim cn As New
> OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;Data
>> > Source=C:\whate ver.mdb")
>> > cn.Open()
>> > cn.Close()
>> > Try
>> > Catch ex As Exception
>> > Finally
>> > If Not cn Is Nothing AndAlso cn.State = ConnectionState .Open >> > Then
>> > MessageBox.Show ("Is showed when cn.close is
>> > disabled")
>> > End If
>> > End Try
>> > ///
>> >
>> >
>>
>>
>
>



Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1437
by: Markus Franz | last post by:
Hi. Today I created a script called load.py for using at the command line written in Python 2.3. This script should load as many websites as given on the comand line and print them with a seperation string to stdout. The loading was done in parallel. (I used processes for this.) The script was started by the following command:
2
1477
by: Neil | last post by:
I have a strange situation. I have a stored procedure that is hanging upon execution, but only some machines and not others. The db is an Access 2000 MDB using ODBC linked tables and a SQL 7 back end. The sp is executed as a pass-through. The sp is fairly simple: UPDATE CUSTOMER SET LastMergeName = . FROM (CUSTOMER C INNER JOIN MergeItems I ON C. = I.)
3
2356
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ---------------------------------------------- //example 1: typedef int t_Array; int main(int argc, char* argv)
31
2615
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
5
2241
by: Hatul Shilgy | last post by:
Hi I'm facing a very strange problem here. My code looks like this if(A == null return doSomethingWith(A.b) When I run my code (in debug mode), I get a NullReferenceException -- and on breaking, I discover that A is indeed null. (The exception is raised in the doSomethingWith line.
5
3066
by: Praveen_db2 | last post by:
Hi All db2 8.1.3 Windows I have folowing table structures CREATE TABLE tb_RTB( EMP_ID INTEGER, DESC VARCHAR(20)); CREATE TABLE tb_ERROR( SQL_STATE CHAR(5), SQL_DESC VARCHAR(20),
23
1617
by: g.ankush1 | last post by:
#include <stdio.h> /* 1st example int a() { return 1; }
8
1679
by: matthewperpick | last post by:
Check out this toy example that demonstrates some "strange" behaviour with keyword arguments and inheritance. ================================= class Parent: def __init__(self, ary = ): self.ary = ary def append(self):
8
5310
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.