-
Jul 30th, 2012, 10:29 AM
#1
Thread Starter
Member
Convert Timer to decimal or int
Hello,
I've been having a hell of a time trying to find this anywhere on the web done proper. Just curious if there is a way to convert a timer to a decimal or int. ?
Thanks for any help!
-
Jul 30th, 2012, 10:38 AM
#2
Re: Convert Timer to decimal or int
What does that even mean? A timer is a component, how can it be converted to either decimal or int? The interval is already int, and can't reasonably be anything else, but what would you expect for converting a timer?
My usual boring signature: Nothing
-
Jul 30th, 2012, 10:38 AM
#3
Fanatic Member
Re: Convert Timer to decimal or int
Do you mean that you're using a timer control from the toolbox and you want to 'convert' that to an int ?
That isn't going to work. A Timer is an object with a ton of properties and events.
Now, you 'can' get (and/or set) some of the timer's properties as an int but not the timer itself.
But maybe if you explain what you're trying to do somebody will be able to advise.
-
Jul 30th, 2012, 12:56 PM
#4
Thread Starter
Member
Re: Convert Timer to decimal or int
Sorry.
What I am doing is having a timer running called TotalTimer. I have this output to a non-visable textbox called TotalTimerBox. What I want to do is convert that value to a int or dec to be used for calculations.
If Now.TimeOfDay >= NineTime And Now.TimeOfDay <= TenTime Then
NineToTen += 1
Production += 1
End If
If Now.TimeOfDay >= TenTime And Now.TimeOfDay <= ElevenTime Then
TenToEleven += 1
Production += 1
End If
If Now.TimeOfDay >= ElevenTime And Now.TimeOfDay <= TweleveTime Then
ElevenToTwelve += 1
Production += 1
End If
Dim ProductionTime As Integer = (TotalTime)
Dim TotalProduction As Integer
TotalTime = ProductionTime / 60
TotalProduction = ProductionTime / Production
Label16.Text = TotalProduction.ToString
This is the code I was trying to use
-
Jul 30th, 2012, 12:58 PM
#5
Thread Starter
Member
Re: Convert Timer to decimal or int
This all happens on a click event
-
Jul 30th, 2012, 01:00 PM
#6
Thread Starter
Member
Re: Convert Timer to decimal or int
This is the error i recieve Conversion from string "00:00:22.0791017" to type 'Integer' is not valid.
-
Jul 30th, 2012, 01:02 PM
#7
Re: Convert Timer to decimal or int
You can convert a DateTime to/from an integer (Int64 or long) with the .ToBinary/.FromBinary method.
There are various ways of representing time only as a real. Several implementations (all of which seem old) can be found with google.
In case that's what you're talking about instead of a Timer.
Regards Tom
#EDIT: Excellent - posted this while the OP made 3 posts
In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)
-
Jul 30th, 2012, 01:33 PM
#8
Re: Convert Timer to decimal or int
Originally Posted by jbailey01
This is the error i recieve Conversion from string "00:00:22.0791017" to type 'Integer' is not valid.
That string looks like a timespan. If it in fact is, you can parse it to a timespan object and then you can perform calculation on it.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 30th, 2012, 02:04 PM
#9
Re: Convert Timer to decimal or int
What is the point of a non-visible textbox? That would just be a woefully inefficient String variable, which isn't a great way to hold an integer or a date, and isn't a particularly good way to hold a string, either.
As for the error, what line are you getting that on?
As a general suggestion, the error strongly suggests that you don't have Option Strict ON. Option Strict will not allow you to make implicit conversions, which are slow and error prone. Therefore, turning Option Strict ON will cause you to write safer, faster, code by enforcing good habits when it comes to data types and type conversions.
My usual boring signature: Nothing
-
Jul 30th, 2012, 02:23 PM
#10
Thread Starter
Member
Re: Convert Timer to decimal or int
I think i need to rethink my strategy on this one. Thanks for the help everyone
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|