Results 1 to 10 of 10

Thread: Convert Timer to decimal or int

  1. #1

    Thread Starter
    Member jbailey01's Avatar
    Join Date
    Jul 2012
    Posts
    45

    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!

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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

  3. #3
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    739

    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.

  4. #4

    Thread Starter
    Member jbailey01's Avatar
    Join Date
    Jul 2012
    Posts
    45

    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

  5. #5

    Thread Starter
    Member jbailey01's Avatar
    Join Date
    Jul 2012
    Posts
    45

    Re: Convert Timer to decimal or int

    This all happens on a click event

  6. #6

    Thread Starter
    Member jbailey01's Avatar
    Join Date
    Jul 2012
    Posts
    45

    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.

  7. #7
    Fanatic Member ThomasJohnsen's Avatar
    Join Date
    Jul 2010
    Location
    Denmark
    Posts
    528

    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)

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: Convert Timer to decimal or int

    Quote Originally Posted by jbailey01 View Post
    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 -

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    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

  10. #10

    Thread Starter
    Member jbailey01's Avatar
    Join Date
    Jul 2012
    Posts
    45

    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
  •  



Click Here to Expand Forum to Full Width