Documente Academic
Documente Profesional
Documente Cultură
Iqbal
Things to Cover
Robots
Teach pendent
GP
Tracks
Create Path and Track
Collision detection
Introduction to VBA
Use of macro create box, delete and move
Attaching macro with GP
Introduction to Forms
Moving of Conveyor belt
Dr J.Iqbal
Introduction to VBA
OVERVIEW
VBA stands for Visual Basic for Applications. It is a
programming language that is produced by Microsoft.
VBA consists of Classes/objects, which are collections
of Properties, Methods, and Events.
Properties are settings of an object that you can check
or change.
Methods are actions the object can perform.
Events are things that happen to an object. An event is
an action recognized by an object.
Dr J.Iqbal
Introduction to VBA
Objects
An object represents an instance of a class such as
Form, Control, or Component. In Visual Basic code, you
must instantiate an object before you can apply one of
the object's methods or change the value of one of its
properties.
Instantiation is the process by which an instance of a
class is created and assigned to an object variable. An
example is shown below:
Dim x As New MyClass()
Dr J.Iqbal
Introduction to VBA
Properties
A property is an attribute of an object that defines one
of the object's characteristics, such as size, color, or
screen location, or an aspect of its behavior, such as
whether it is enabled or visible. To change the
characteristics of an object, you change the values of its
corresponding properties.
To set the value of a property, affix the reference to an
object with a period, the property name, an equal sign
(=), and the new property value.
Public Sub ChangeName(newTitle)
myForm.Text = newTitle
End Sub
Dr J.Iqbal
Introduction to VBA
Methods
A method is an action that an object can perform. For
example, Add is a method of the ComboBox object,
because it adds a new entry to a combo box.
The following example demonstrates the Start method
of a Timer component:
' Instantiates a Timer object.
Dim myTimer As New System.Windows.Forms.Timer()
' Invokes the Start method of myTimer.
MyTimer.Start
Dr J.Iqbal
Introduction to VBA
Events
An event is an action recognized by an object, such as
clicking the mouse or pressing a key, and for which you
can write code to respond.
Events can occur as a result of a user action or program
code, or they can be triggered by the system. You can
also develop your own custom events to be raised by
your objects and handled by other objects.
Dr J.Iqbal
Introduction to VBA
OVERVIEW
VBA can be used in Workspace to create Macros,
Behaviors, Tool Behaviors, and robot programs using
Workspaces customizable robot language.
Programs or commands written in VBA can be used to
access Workspace functionality via the Workspace
Object Model.
The entire Object Model is included in the User
Manual.
Dr J.Iqbal
Introduction to VBA
When a command from the Workspace Object Model
is executed within a VBA program it makes a call into
the main Workspace executable. This way the user can
access and manipulate data and functions within
Workspace from a VBA program.
All macros and programs are constructed in the VBA
Integrated Development Environment (IDE).
The IDE is built into Workspace and may be started
within the Workspace environment. However, the IDE
has its own help system, menu structure, and
commands.
Dr J.Iqbal
Introduction to VBA
The IDE is divided into three main areas the Project
Explorer, the Properties Window, and the Main
Working Area.
The Project Explorer is located on the upper left-hand
side of the screen below the icons.
The Project Explorer window presents the user with a
hierarchical structure of all VBA projects, Workspace objects,
modules and Class modules.
Introduction to VBA
The Main Working Area is the large gray section in the
middle of the screen.
The Main Working Area contains the object of interest, such
as opened VBA Modules, Watches, and UserForms.
Macros
OVERVIEW
Macros are Code Modules that contain a series of Methods and
Properties arranged to achieve a desired goal.
Macros can be run from the Run Macros dialog box, from the
Command Line, or as GP Actions.
Dr J.Iqbal
Create_mov_del.wsp
EXAMPLE
If there are any Workspace projects open, close them and open
a new project.
Select Options \ Visual Basic
Result: The IDE is opened.
In the Project Explorer right click on the name of the VBA project
(it will have the same name as the Workspace Project).
Select Insert \ Module.
Result: A Code Module is opened and placed in the Main Working
Area.
Click the mouse in the Code Module and type the line sub
mybox() and press enter.
Result: The IDE adds the line End Sub automatically, and the cursor
is placed between the two lines.
Note: mybox will be the name of the macro.
Dr J.Iqbal
Macro
Create Box
Sub myBox()
ThisDocument.Box "box", 300, 300, 300
End Sub
Dr J.Iqbal
Right click and select List Properties\Methods.
Result: A Drop-Down Menu lists all of the available options.
Select ThisDocument
Result: ThisDocument is added to the macro.
Type .
Result: Another Drop-Down Menu appears listing the available options now.
Select Box
Result: Box is added after the period.
Type box,100,100,100
In the command line section at the bottom of the screen type box
Dr J.Iqbal
Result: The macro is run again.
Macro
Create Box
Sub myBox()
ThisDocument.Box "box", 300, 300, 300
End Sub
Delete Box
Sub delete()
ThisDocument.CadObject(box").Delete
End Sub
Dr J.Iqbal
Dr J.Iqbal
Create_mov_delete form.wsp
Dr J.Iqbal
Use of forms
From the Tool Box to the left of the UserForm select Frame.
Note: If you are not sure which icons in the Tool Box are for which
object, hold your mouse over the icon and a label will appear.
The toolbox can be switched on and off from the View menu.
Left click the mouse near the top left-hand corner of the
UserForm, and holding down the left mouse button drag the
mouse to the lower right-hand corner of the UserForm.
Result: A Frame is created on the UserForm
Note: A Frame is a visual means of grouping objects together. Dr J.Iqbal
Repeat steps the above four steps and label the other Text
Boxes Y and Z.
Resize the Frame so that it contains just the three Text Boxes
and their Labels.
Dim x As Double
Dim y As Double
Dim z As Double
Rem Get coordinates from the text boxes
x = TextBox1.Text
y = TextBox2.Text
z = TextBox3.Text
Rem Position the CAD object
ThisDocument.CADObject("box").MoveAbsolute x, y, z
Add the line Hide between the two already existing lines.
Result: The UserForm is now complete. All that is left to do is to
create the macro that displays it.
Dr J.Iqbal
Select MoveBoxDialog
Type .
Select Show.
Create_mov_delete form
Dr J.Iqbal
Dr J.Iqbal
ThisDocument.Box name, x, y, z
End Sub
Dr J.Iqbal
Move Absolute
Private Sub CommandButton1_Click()
Dim x As Double
Dim y As Double
Dim z As Double
x = TextBox1.Text
y = TextBox2.Text
z = TextBox3.Text
name = TextBox7.Text
ThisDocument.CadObject(name).MoveAbsolute x, y, z
Rem x, y, z
End Sub
Dr J.Iqbal
Move Relative
Private Sub MoveRelativeButton_Click()
name = TextBox7.Text
ThisDocument.CadObject(name).MoveRelative x, y, z
End Sub
Dr J.Iqbal
Delete Box
Private Sub deleteButton_Click()
name = TextBox7.Text
ThisDocument.CadObject(name).Delete
End Sub
Exit
Dr J.Iqbal
Explicit
option force
you to
declare var
before using
Dr J.Iqbal
Dr J.Iqbal
Dr J.Iqbal
Dr J.Iqbal
Dr J.Iqbal
Dr J.Iqbal
Dr J.Iqbal
Demo
Wspace. Wspacefolder.g10finalwithoutlang
Wspace. Demo
Dr J.Iqbal