Solved

Casting from Long to TimeSpan in vb.net

Posted on 2011-09-05
3
580 Views
Last Modified: 2012-05-12
In VB.net - I am trying to cast a Long datatype to TimeSpan - I cannot seem to do this using ctype or directcast - any ideas?
0
Comment
Question by:Jedeye
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
x77 earned 334 total points
ID: 36483056
You can build a Date or a Timespan from a long, you do´nt need cast.
Date an TimeSpan have constructor from Long (Ticks).

   Dim MyDate as new Date(TicksValue)
   Dim MyTimeSpan as new TimeSpan(TicksValue)
0
 
LVL 15

Assisted Solution

by:x77
x77 earned 334 total points
ID: 36483099
You can also adjust a TimeSpan or a Date variable from a long (TicksValue) using Ticks Property.

   myTimeSpan.Ticks = TiksValue.

You can´nt cast a timespan as it is a ValueType.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 166 total points
ID: 36483113
Depends on what is in your Long: ticks, minutes, seconds, days, months...

Use the constructor that enables you to pass the information:

For ticks: Dim myTimeSpan As New TimeSpan(yourLong)
For minutes: Dim myTimeSpan As New TimeSpan(0, CInt(yourLong), 0)
For days: Dim myTimeSpan As New TimeSpan(CInt(yourLong),0,0,0)
For milliseconds: Dim myTimeSpan As New TimeSpan(0, 0, 0, 0, CInt(yourLong))
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now