473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Spot the error (ie I can't)

Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please Enter
the Start of the Holiday")

If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then

While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)

MsgBox("The date you have entered does not occur between the
shifts specified on that day.")

fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the
Start of the Holiday")

If IsNothing(fromdate) Then

Exit While

End If

End While

End if

My dialog just gets a date time. It returns nothing for a failure.

I tried making the if statement " if not IsNothing(fromDate) then" and this
still ran, so I tried the godawful combination that I have now.

Now I have checked in the debugger, the statement "(Not
fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) " is false. This
means that the if statement shouldn't run.

HOWEVER the statement ALWAYS enters the if statement block. Before you ask,
I have written an else statement and NOT clicked cancel and this results in
the statement returning true, and THEN entering the if block (not the else
block). Its as if its discarding the if statement and just entering anyway.

For the life of me I cannot spot this error, and I'm on the managed MSDN so
I'd really appreciate some help here from MVP/MSFT.

Cheers.
Jan 11 '07 #1
8 1121
More info.

I disabled Compiler optomizations (just in case it was optimizing the if
statement to permanently true) and this still results in the exact same
behaviour.
"Steven Spencer (Spinalogic)" <Sp***************@newsgroup.nospamwrote in
message news:OZ**************@TK2MSFTNGP03.phx.gbl...
Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please Enter
the Start of the Holiday")

If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then

While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)

MsgBox("The date you have entered does not occur between the
shifts specified on that day.")

fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the
Start of the Holiday")

If IsNothing(fromdate) Then

Exit While

End If

End While

End if

My dialog just gets a date time. It returns nothing for a failure.

I tried making the if statement " if not IsNothing(fromDate) then" and
this still ran, so I tried the godawful combination that I have now.

Now I have checked in the debugger, the statement "(Not
fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) " is false.
This means that the if statement shouldn't run.

HOWEVER the statement ALWAYS enters the if statement block. Before you
ask, I have written an else statement and NOT clicked cancel and this
results in the statement returning true, and THEN entering the if block
(not the else block). Its as if its discarding the if statement and just
entering anyway.

For the life of me I cannot spot this error, and I'm on the managed MSDN
so I'd really appreciate some help here from MVP/MSFT.

Cheers.


Jan 11 '07 #2
VB.net
..net 1.1 SP1

That may be helpful/neccessary.
"Steven Spencer (Spinalogic)" <Sp***************@newsgroup.nospamwrote in
message news:OZ**************@TK2MSFTNGP03.phx.gbl...
Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please Enter
the Start of the Holiday")

If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then

While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)

MsgBox("The date you have entered does not occur between the
shifts specified on that day.")

fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the
Start of the Holiday")

If IsNothing(fromdate) Then

Exit While

End If

End While

End if

My dialog just gets a date time. It returns nothing for a failure.

I tried making the if statement " if not IsNothing(fromDate) then" and
this still ran, so I tried the godawful combination that I have now.

Now I have checked in the debugger, the statement "(Not
fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) " is false.
This means that the if statement shouldn't run.

HOWEVER the statement ALWAYS enters the if statement block. Before you
ask, I have written an else statement and NOT clicked cancel and this
results in the statement returning true, and THEN entering the if block
(not the else block). Its as if its discarding the if statement and just
entering anyway.

For the life of me I cannot spot this error, and I'm on the managed MSDN
so I'd really appreciate some help here from MVP/MSFT.

Cheers.


Jan 11 '07 #3
If todate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0 Then Exit Sub

I've tried this line, verified in the debugger that todate.CompareTo(New
DateTime(1, 1, 1, 1, 1, 1, 1)) = 0 is true, yet this does not execute exit
sub

when it's false, it still doesn't run the exit sub (correctly) but there
isn't an inversion happening.

"Steven Spencer (Spinalogic)" <Sp***************@newsgroup.nospamwrote in
message news:%2***************@TK2MSFTNGP06.phx.gbl...
VB.net
.net 1.1 SP1

That may be helpful/neccessary.
"Steven Spencer (Spinalogic)" <Sp***************@newsgroup.nospamwrote
in message news:OZ**************@TK2MSFTNGP03.phx.gbl...
>Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please
Enter the Start of the Holiday")

If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then

While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)

MsgBox("The date you have entered does not occur between the
shifts specified on that day.")

fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the
Start of the Holiday")

If IsNothing(fromdate) Then

Exit While

End If

End While

End if

My dialog just gets a date time. It returns nothing for a failure.

I tried making the if statement " if not IsNothing(fromDate) then" and
this still ran, so I tried the godawful combination that I have now.

Now I have checked in the debugger, the statement "(Not
fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) " is false.
This means that the if statement shouldn't run.

HOWEVER the statement ALWAYS enters the if statement block. Before you
ask, I have written an else statement and NOT clicked cancel and this
results in the statement returning true, and THEN entering the if block
(not the else block). Its as if its discarding the if statement and just
entering anyway.

For the life of me I cannot spot this error, and I'm on the managed MSDN
so I'd really appreciate some help here from MVP/MSFT.

Cheers.



Jan 11 '07 #4
Spotted!!!!!!!

The first issue is that assigning Nothing to a variable of type DateTime is
the same as assigning 01/01/0001 12:00:00 AM to it, i.e., Midnight (being
the start of the day) on the 1st of January in the year 1.

Dim _d As DateTime = Nothing
Dim _d As DateTime = New DateTime(1, 1, 1)
Dim _d As DateTime = New DateTime(1, 1, 1, 0, 0, 0, 0)
Dim _d As DateTime = DateTime.MinValue

to name just a few ways of initialising a variable of type DateTime and all
thiose shown result in _d having the same value.

The second issue is that you are comparing fromdate to 01/01/0001
01:01:01.001 AM. When the dialog 'fails', this test results in a value of -1
(fromdate (01/01/0001 12:00:00 AM is less than 01/01/0001 01:01:01.001 AM)
and therfore your boolean expression equates to True and the code inside the
If ... End If is executed as you are observing.

I would be inclined to recode it so that it is something like:

Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please Enter
the Start of the Holiday")

If fromdate <DateTime.MinValue Then
While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)
MessageBox.Show("The date you have entered does not occur between the
shifts specified on that day.", "Invalid Value")
fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the Start
of the Holiday")
If fromdate <DateTime.MinValue Then Continue
End While
End If
"Steven Spencer (Spinalogic)" <Sp***************@newsgroup.nospamwrote in
message news:OZ**************@TK2MSFTNGP03.phx.gbl...
Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please Enter
the Start of the Holiday")

If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then

While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)

MsgBox("The date you have entered does not occur between the
shifts specified on that day.")

fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the
Start of the Holiday")

If IsNothing(fromdate) Then

Exit While

End If

End While

End if

My dialog just gets a date time. It returns nothing for a failure.

I tried making the if statement " if not IsNothing(fromDate) then" and
this still ran, so I tried the godawful combination that I have now.

Now I have checked in the debugger, the statement "(Not
fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) " is false.
This means that the if statement shouldn't run.

HOWEVER the statement ALWAYS enters the if statement block. Before you
ask, I have written an else statement and NOT clicked cancel and this
results in the statement returning true, and THEN entering the if block
(not the else block). Its as if its discarding the if statement and just
entering anyway.

For the life of me I cannot spot this error, and I'm on the managed MSDN
so I'd really appreciate some help here from MVP/MSFT.

Cheers.


Jan 11 '07 #5
Seeing as you're on Framework 1.1 the line:

If fromdate <DateTime.MinValue Then Continue

should read:

If fromdate = DateTime.MinValue Then Exit While

It would have been nice if you had included that information in your
original post.
"Stephany Young" <noone@localhostwrote in message
news:Ox**************@TK2MSFTNGP06.phx.gbl...
Spotted!!!!!!!

The first issue is that assigning Nothing to a variable of type DateTime
is the same as assigning 01/01/0001 12:00:00 AM to it, i.e., Midnight
(being the start of the day) on the 1st of January in the year 1.

Dim _d As DateTime = Nothing
Dim _d As DateTime = New DateTime(1, 1, 1)
Dim _d As DateTime = New DateTime(1, 1, 1, 0, 0, 0, 0)
Dim _d As DateTime = DateTime.MinValue

to name just a few ways of initialising a variable of type DateTime and
all thiose shown result in _d having the same value.

The second issue is that you are comparing fromdate to 01/01/0001
01:01:01.001 AM. When the dialog 'fails', this test results in a value
of -1 (fromdate (01/01/0001 12:00:00 AM is less than 01/01/0001
01:01:01.001 AM) and therfore your boolean expression equates to True and
the code inside the If ... End If is executed as you are observing.

I would be inclined to recode it so that it is something like:

Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please
Enter the Start of the Holiday")

If fromdate <DateTime.MinValue Then
While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)
MessageBox.Show("The date you have entered does not occur between the
shifts specified on that day.", "Invalid Value")
fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the Start
of the Holiday")
If fromdate <DateTime.MinValue Then Continue
End While
End If
"Steven Spencer (Spinalogic)" <Sp***************@newsgroup.nospamwrote
in message news:OZ**************@TK2MSFTNGP03.phx.gbl...
>Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please
Enter the Start of the Holiday")

If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then

While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)

MsgBox("The date you have entered does not occur between the
shifts specified on that day.")

fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the
Start of the Holiday")

If IsNothing(fromdate) Then

Exit While

End If

End While

End if

My dialog just gets a date time. It returns nothing for a failure.

I tried making the if statement " if not IsNothing(fromDate) then" and
this still ran, so I tried the godawful combination that I have now.

Now I have checked in the debugger, the statement "(Not
fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) " is false.
This means that the if statement shouldn't run.

HOWEVER the statement ALWAYS enters the if statement block. Before you
ask, I have written an else statement and NOT clicked cancel and this
results in the statement returning true, and THEN entering the if block
(not the else block). Its as if its discarding the if statement and just
entering anyway.

For the life of me I cannot spot this error, and I'm on the managed MSDN
so I'd really appreciate some help here from MVP/MSFT.

Cheers.



Jan 11 '07 #6
I'm actually a java programmer by trade.

I HATE VB.net

C# is sooo much nicer.

But yes, it was a goddamn reference type thing.
It SAID it was 12:00am in the debugger which is the value I replicated.. I
however had failed to identify the problem as I used the IsNothing(blah)
function on the datetime. Which returned false.

I changed the code to read fromdate = nothing and then this worked
correctly.

I do hope to all god that the only reason the reference type/value type
stuff is there is for VB6.0 compatibility otherwise whoever did it at MS
needs to be shot. And my employer doesn't know how to read C# and we have
WAY to much code to change right now. Thanks for your help though.

++karma
"Stephany Young" <noone@localhostwrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
Seeing as you're on Framework 1.1 the line:

If fromdate <DateTime.MinValue Then Continue

should read:

If fromdate = DateTime.MinValue Then Exit While

It would have been nice if you had included that information in your
original post.
"Stephany Young" <noone@localhostwrote in message
news:Ox**************@TK2MSFTNGP06.phx.gbl...
>Spotted!!!!!!!

The first issue is that assigning Nothing to a variable of type DateTime
is the same as assigning 01/01/0001 12:00:00 AM to it, i.e., Midnight
(being the start of the day) on the 1st of January in the year 1.

Dim _d As DateTime = Nothing
Dim _d As DateTime = New DateTime(1, 1, 1)
Dim _d As DateTime = New DateTime(1, 1, 1, 0, 0, 0, 0)
Dim _d As DateTime = DateTime.MinValue

to name just a few ways of initialising a variable of type DateTime and
all thiose shown result in _d having the same value.

The second issue is that you are comparing fromdate to 01/01/0001
01:01:01.001 AM. When the dialog 'fails', this test results in a value
of -1 (fromdate (01/01/0001 12:00:00 AM is less than 01/01/0001
01:01:01.001 AM) and therfore your boolean expression equates to True and
the code inside the If ... End If is executed as you are observing.

I would be inclined to recode it so that it is something like:

Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please
Enter the Start of the Holiday")

If fromdate <DateTime.MinValue Then
While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)
MessageBox.Show("The date you have entered does not occur between
the shifts specified on that day.", "Invalid Value")
fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter the Start
of the Holiday")
If fromdate <DateTime.MinValue Then Continue
End While
End If
"Steven Spencer (Spinalogic)" <Sp***************@newsgroup.nospamwrote
in message news:OZ**************@TK2MSFTNGP03.phx.gbl...
>>Dim dlg As New dlgChangeDate

Dim fromdate As DateTime = dlg.GetaDate(System.DateTime.Now, "Please
Enter the Start of the Holiday")

If (Not fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) Then

While IsDateBetweenShifts(fromdate, cboHolidayDoctors.SelectedValue)

MsgBox("The date you have entered does not occur between the
shifts specified on that day.")

fromdate = dlg.GetaDate(System.DateTime.Now, "Please Enter
the Start of the Holiday")

If IsNothing(fromdate) Then

Exit While

End If

End While

End if

My dialog just gets a date time. It returns nothing for a failure.

I tried making the if statement " if not IsNothing(fromDate) then" and
this still ran, so I tried the godawful combination that I have now.

Now I have checked in the debugger, the statement "(Not
fromdate.CompareTo(New DateTime(1, 1, 1, 1, 1, 1, 1)) = 0) " is false.
This means that the if statement shouldn't run.

HOWEVER the statement ALWAYS enters the if statement block. Before you
ask, I have written an else statement and NOT clicked cancel and this
results in the statement returning true, and THEN entering the if block
(not the else block). Its as if its discarding the if statement and
just entering anyway.

For the life of me I cannot spot this error, and I'm on the managed MSDN
so I'd really appreciate some help here from MVP/MSFT.

Cheers.




Jan 11 '07 #7
On 2007-01-11, Steven Spencer (Spinalogic) <Sp***************@newsgroup.nospamwrote:
I'm actually a java programmer by trade.

I HATE VB.net

C# is sooo much nicer.

But yes, it was a goddamn reference type thing.
It SAID it was 12:00am in the debugger which is the value I replicated.. I
however had failed to identify the problem as I used the IsNothing(blah)
function on the datetime. Which returned false.

I changed the code to read fromdate = nothing and then this worked
correctly.

I do hope to all god that the only reason the reference type/value type
stuff is there is for VB6.0 compatibility otherwise whoever did it at MS
needs to be shot. And my employer doesn't know how to read C# and we have
WAY to much code to change right now. Thanks for your help though.
Sorry to disappoint you, but the reference type vs value type stuff is not a
..NET thing and has nothing to do with VB.NET. The same thing would happen in
C#.

They have added "Nullable Types" in .NET 2.0:

Dim myNullableDate As Nullable(Of DateTime) = Nothing

The syntax is cleaner in C#:
DateTime? myNullableDate = null;

--
Tom Shelton
Jan 11 '07 #8
When the hell is someone going to make an object oriented language that is
actually FULLY OO.

Same stuff in C#. Well you learn something every day.

:'(
"Tom Shelton" <to*********@comcastXXXXXXX.netwrote in message
news:Te******************************@comcast.com. ..
On 2007-01-11, Steven Spencer (Spinalogic)
<Sp***************@newsgroup.nospamwrote:
>I'm actually a java programmer by trade.

I HATE VB.net

C# is sooo much nicer.

But yes, it was a goddamn reference type thing.
It SAID it was 12:00am in the debugger which is the value I replicated..
I
however had failed to identify the problem as I used the IsNothing(blah)
function on the datetime. Which returned false.

I changed the code to read fromdate = nothing and then this worked
correctly.

I do hope to all god that the only reason the reference type/value type
stuff is there is for VB6.0 compatibility otherwise whoever did it at MS
needs to be shot. And my employer doesn't know how to read C# and we
have
WAY to much code to change right now. Thanks for your help though.

Sorry to disappoint you, but the reference type vs value type stuff is not
a
.NET thing and has nothing to do with VB.NET. The same thing would happen
in
C#.

They have added "Nullable Types" in .NET 2.0:

Dim myNullableDate As Nullable(Of DateTime) = Nothing

The syntax is cleaner in C#:
DateTime? myNullableDate = null;

--
Tom Shelton

Jan 14 '07 #9

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

Similar topics

2
by: pasa | last post by:
I'm an old time python user, but just got bitten by namespaces in eval. If this is an old discussion somewhere, feel free to point me there. Based on the documentation, I would have expected the...
0
by: Karam Chand | last post by:
Greetings I have a table and I want to make a copy of it in the same database. I only keep the structure and indexes and not the data. I issue a command - create table...
3
by: Aaron Brockhurst | last post by:
Hi Can anyone help? I cant get my php script to insert or delete records into a mysql table. I can view them all fine but that's about it. I've checked the user permissions on mysql and...
1
by: JMCN | last post by:
hello i receive a runtime error '2465' whenever i run my module in access 97. it says 'Run-time error '2465' OOB Reports can't find the field "DuplicatePayments' referred to in your...
1
by: ravi | last post by:
I have created the following interest to calculate the interest for the following currency pairs. I have tried to combine them in macros using conditions but the next query that is run in the macro...
0
by: Tony Lewis | last post by:
I'm running IIS on a Windows 2k server and have just installed the .NET framework 1.1 so I can deploy ASP.NET applications on my server through .NET Studios. All my normal ASP applications run fine...
1
by: Eric | last post by:
This program is running fine in my office i just copy it and run at home it start given that error and highlight Chr(13). I dont know is this is what the error is or some thing else Compiler...
2
by: Mark Cummings | last post by:
I am migrating an Oracle 9i to Oracle 10g database, and Perl 5.0.4 to Perl 5.8.7 in Sun Solaris environment. Using Perl 5.8.7, the following legacy code segment is returning a '-1' return code on...
4
by: ramaswamynanda | last post by:
Hello All, I have developed an application using Ms Access 2000. My client has Access 2003. I shipped him the code yesterday and he got an error hile running the application via the mdb file...
1
by: veer | last post by:
hi i made program which calculates the time of every user works in particular SQL server and the exe of this program works fine only on those system which have vb6.0 installed but when i run this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.