473,387 Members | 3,787 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,387 software developers and data experts.

TimeSpan.zero

i translate a C# funtion to VB.NET and i have this :

Shared Function isAllDay(ByVal ap As Appointment) As Boolean
Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso
ap.DateEnd.TimeOfDay = TimeSpan.Zero
End Function

Error :
= is not corret

so i try " is TimeSpan.zero"

Error again ?!!!

Nov 24 '05 #1
2 2921
"ucasesoftware" <uc***********@hotmail.fr> schrieb
i translate a C# funtion to VB.NET and i have this :

Shared Function isAllDay(ByVal ap As Appointment) As Boolean
Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso ap
.DateEnd.TimeOfDay = TimeSpan.Zero
End Function

Error :
= is not corret

so i try " is TimeSpan.zero"

Error again ?!!!


Return timespan.equals(ap.DateBegin.TimeOfDay, TimeSpan.Zero) _
AndAlso timespan.equals(ap.DateEnd.TimeOfDay, TimeSpan.Zero)
Or simpler:

Return ap.DateBegin.TimeOfDay.ticks = 0 _
AndAlso ap.DateEnd.TimeOfDay.ticks = 0
Armin
Nov 24 '05 #2

ucasesoftware,
In addition to the other comments.

The C# code is relying on overloaded operators. The = operator is overloaded
in the TimeSpan class to support comparing 2 TimeSpan values.

ap.DateBegin.TimeOfDay is a TimeSpan

TimeSpan.Zero is also a TimeSpan.

The C# compiler is using TimeSpan.op_Equal to compare the two values.
op_Equal is the special name for the overloaded = operator.

As Armin shows in VB 2002 & 2003 you need to use TimeSpan.Equals,
TimeSpan.Compare, or TimeSpan.op_Equals to compare the two values.

Fortunately! (Hurrah!) VB 2005 fully supports overloaded operators so you
can use your code "as is".
NOTE: Be careful with the Equals method & structures, such as TimeSpan, as
Equals overridden from System.Object takes Object parameters & will cause
boxing. I normally offer type safe Equals methods on my structures so as to
avoid this boxing. In the case of TimeSpan.Equals(x, y) there is an overload
that accepts TimeSpans hence avoiding the boxing.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"ucasesoftware" <uc***********@hotmail.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
|i translate a C# funtion to VB.NET and i have this :
|
| Shared Function isAllDay(ByVal ap As Appointment) As Boolean
| Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso
| ap.DateEnd.TimeOfDay = TimeSpan.Zero
| End Function
|
| Error :
| = is not corret
|
| so i try " is TimeSpan.zero"
|
| Error again ?!!!
|
Nov 28 '05 #3

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

Similar topics

3
by: Ivan A. | last post by:
Hi! Why I can't serialize TimeSpan structure with XmlSerializer? This is what I do: using System; using System.IO; using System.Xml; using System.Xml.Serialization;
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
10
by: Charles Law | last post by:
If I display a TimeSpan I get something like 00:05:17.6217891 when what I would like to see is 00:05:18 Is there an easy way to get this output? Try as I might I just can't find it.
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
3
by: Rob Meade | last post by:
Hi all, I'm having a bit of trouble with the following function.... Private Function GetSystemUpTime() As TimeSpan ' declare variables Dim Result As TimeSpan Dim PerformanceCounter As...
1
by: David | last post by:
Hi, using .NET 1.1 C# I am trying to determine page generation time. I have TimeSpan RenderTime = DateTime.Now - PageTime; (pagetime was set up in oninit, Rendertime is in the render I am...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
11
by: Michael C | last post by:
IS there a reason Timespan doesn't have an operator for divide? Being that it's an amount of time I would have thought it should. Really it's just a wrapper around a double variable? Thanks,...
2
by: shapper | last post by:
Hello, I have the following: boxStat = new BoxStat { BoxCount = database.Boxes.Count(), SinceLastCreate = (DateTime.Now - database.Boxes.Max(b => b.CreatedAt)).Days ?? 0 };
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.