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!
Printable View
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!
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?
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.
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
This all happens on a click event
This is the error i recieve Conversion from string "00:00:22.0791017" to type 'Integer' is not valid.
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 :)
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.
I think i need to rethink my strategy on this one. Thanks for the help everyone