Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Casting from Long to TimeSpan in vb.net

Posted on 2011-09-05
3
Medium Priority
?
657 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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