?
Solved

Casting from Long to TimeSpan in vb.net

Posted on 2011-09-05
3
Medium Priority
?
642 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
x77 earned 1336 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 1336 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 664 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

777 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