# How to measure the Motion Time inVB/ API?

**URL:** <https://tech-community.robotics.abb.com/t/how-to-measure-the-motion-time-invb-api/66>\
**Category:** RobotStudio S4\
**Created:** [July 14, 2003, 9:16am UTC](https://tech-community.robotics.abb.com/t/how-to-measure-the-motion-time-invb-api/66 "2003-07-14T09:16:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![behnam](https://avatars.discourse-cdn.com/v4/letter/b/b4bc9f/32.png) [@behnam](https://tech-community.robotics.abb.com/u/behnam)\
**Post date:** [July 14, 2003, 9:16am UTC](https://tech-community.robotics.abb.com/t/how-to-measure-the-motion-time-invb-api/66/1 "2003-07-14T09:16:45Z")

</div>

Hi, I got a question. How we can measure Motion Time or Cycle Time in RobotStudio API? I tried to use “events” of “simulation” to measure the time at start of stop of simualtion. but I couldn’t use these events (how should these events be written in VB/API?) and I wonder if you know…

Best regards

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/system/32/6_2.png) [@system](https://tech-community.robotics.abb.com/u/system)\
**Post date:** [July 16, 2003, 10:31am UTC](https://tech-community.robotics.abb.com/t/how-to-measure-the-motion-time-invb-api/66/2 "2003-07-16T10:31:15Z")

</div>

Something like this should solve it…

The way to get events in VBA is to declare an object “WithEvents”, then you will find these events (procedures) in the drop-down list above the code window. In the code below we have declared sim WithEvets, thereafter we select the “Stop” procedure and added the code needed. Before you start the simulation, run the Init method from “ToolMacroMacros…” and browse to your Init method. After the simulation stops the motion time will be logged in a new log called “MotionTime”

Dim WithEvents sim As Simulation  
Dim ctrl As ABBS4Controller

Sub Init()  
Set sim = ActiveStation.Simulations(1)  
Set ctrl = ActiveStation.ActiveMechanism.Controller  
End Sub

Private Sub sim\_Stop()  
Call ActiveStation.PrintLog(“MotionTime”, ctrl.MotionTime)  
End Sub
