Timer function usage in VBA _vbs

Source: Internet
Author: User
Tags current time

The first 1.40 cases of Timer function

First, the topic:

Requires writing a piece of code, using the Timer function to calculate the time the code runs.

Second, code:

Sub Example _1_040 ()
  Dim T, I&, a
  t = Timer for
  i = 1 to 1000000
    a = a + I
  Next i
  MsgBox timer-t & Amp "Seconds"  ' returns 0.046875 seconds end
Sub

Three, code detailed

1. Sub Example _1_040 (): Start statement for Macro program. The macro name is sample _1_040.
2, Dim T, I&, a: Declare variable t,a are variable, i is long integer variable.
3, t = Timer: Assign the time of the system to the variable T.
4, for i = 1 to 1000000: Loop from 1 to 1000000.
5. A = a + I: assigning the a+i value to variable A is actually an additive process.
6, MsgBox timer-t & "Seconds": Use the message box to display the current time minus the time set earlier, get the time to run the entire code.

Timer function

Returns a single that represents the number of seconds from midnight to the current elapsed time.

Timer
Description
In Microsoft windows, the Timer function returns a decimal fraction of a second.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.