VERSION 5.00
Begin VB.Form frmRobot 
   BorderStyle     =   1  '固定(実線)
   Caption         =   "Robot"
   ClientHeight    =   11355
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8670
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   11355
   ScaleWidth      =   8670
   StartUpPosition =   3  'Windows の既定値
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      Height          =   405
      Left            =   7320
      TabIndex        =   6
      Top             =   10800
      Width           =   1215
   End
   Begin VB.Frame Frame2 
      Caption         =   "RobMaster"
      Height          =   9615
      Left            =   120
      TabIndex        =   8
      Top             =   1080
      Width           =   8415
      Begin VB.TextBox txtApproach 
         Height          =   315
         Left            =   5880
         TabIndex        =   69
         Text            =   "1"
         Top             =   4590
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Go!"
         Height          =   375
         Index           =   8
         Left            =   7050
         TabIndex        =   67
         Top             =   5640
         Width           =   1215
      End
      Begin VB.TextBox txtDepart 
         Height          =   315
         Left            =   4920
         TabIndex        =   66
         Text            =   "1"
         Top             =   5670
         Width           =   825
      End
      Begin VB.ComboBox cmbDepartComp 
         Height          =   300
         ItemData        =   "Robot.frx":0000
         Left            =   2280
         List            =   "Robot.frx":000A
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   65
         Top             =   5640
         Width           =   735
      End
      Begin VB.ComboBox cmbDepartPath 
         Height          =   300
         ItemData        =   "Robot.frx":0016
         Left            =   4060
         List            =   "Robot.frx":0023
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   64
         Top             =   5670
         Width           =   735
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Go!"
         Height          =   375
         Index           =   7
         Left            =   7050
         TabIndex        =   62
         Top             =   5040
         Width           =   1215
      End
      Begin VB.TextBox txtApproachVarIndex 
         Height          =   315
         Left            =   4080
         TabIndex        =   61
         Text            =   "1"
         Top             =   4590
         Width           =   825
      End
      Begin VB.ComboBox cmbApproachComp 
         Height          =   300
         ItemData        =   "Robot.frx":0032
         Left            =   2280
         List            =   "Robot.frx":003C
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   60
         Top             =   4590
         Width           =   735
      End
      Begin VB.ComboBox cmbApproachPath 
         Height          =   300
         ItemData        =   "Robot.frx":0048
         Left            =   5040
         List            =   "Robot.frx":0055
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   59
         Top             =   4590
         Width           =   735
      End
      Begin VB.ComboBox cmbApproachVarType 
         Height          =   300
         ItemData        =   "Robot.frx":0064
         Left            =   3240
         List            =   "Robot.frx":0071
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   58
         Top             =   4590
         Width           =   735
      End
      Begin VB.ComboBox cmbSuf 
         Height          =   300
         ItemData        =   "Robot.frx":007E
         Left            =   2280
         List            =   "Robot.frx":0094
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   49
         Top             =   3960
         Width           =   1005
      End
      Begin VB.OptionButton optSuf 
         Caption         =   "Option1"
         Height          =   195
         Index           =   1
         Left            =   1980
         TabIndex        =   48
         Top             =   4020
         Width           =   255
      End
      Begin VB.OptionButton optSuf 
         Caption         =   "Option1"
         Height          =   195
         Index           =   0
         Left            =   1980
         TabIndex        =   47
         Top             =   3570
         Width           =   255
      End
      Begin VB.TextBox txtRotDeg 
         Height          =   315
         Left            =   5310
         TabIndex        =   46
         Text            =   "30.0"
         Top             =   3510
         Width           =   615
      End
      Begin VB.TextBox txtV 
         Height          =   315
         Index           =   2
         Left            =   3900
         TabIndex        =   45
         Text            =   "3"
         Top             =   3510
         Width           =   465
      End
      Begin VB.TextBox txtV 
         Height          =   315
         Index           =   1
         Left            =   3210
         TabIndex        =   44
         Text            =   "2"
         Top             =   3510
         Width           =   465
      End
      Begin VB.TextBox txtV 
         Height          =   315
         Index           =   0
         Left            =   2520
         TabIndex        =   43
         Text            =   "1"
         Top             =   3510
         Width           =   465
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Rotate"
         Height          =   375
         Index           =   6
         Left            =   7080
         TabIndex        =   41
         Top             =   3930
         Width           =   1215
      End
      Begin VB.TextBox txtV 
         Height          =   315
         Index           =   3
         Left            =   6150
         TabIndex        =   40
         Text            =   "0"
         Top             =   3510
         Width           =   525
      End
      Begin VB.ComboBox cmbRotAt 
         Height          =   300
         ItemData        =   "Robot.frx":00B3
         Left            =   4560
         List            =   "Robot.frx":00C0
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   39
         Top             =   3510
         Width           =   735
      End
      Begin VB.ComboBox cmbDrvAt 
         Height          =   300
         ItemData        =   "Robot.frx":00CD
         Left            =   3210
         List            =   "Robot.frx":00DA
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   38
         Top             =   2940
         Width           =   735
      End
      Begin VB.ComboBox cmbJn 
         Height          =   300
         ItemData        =   "Robot.frx":00E7
         Left            =   4060
         List            =   "Robot.frx":00F4
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   37
         Top             =   2940
         Width           =   735
      End
      Begin VB.TextBox txtDrvDeg 
         Height          =   315
         Left            =   4920
         TabIndex        =   35
         Text            =   "30.0"
         Top             =   2940
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Drive"
         Height          =   375
         Index           =   5
         Left            =   7080
         TabIndex        =   34
         Top             =   2910
         Width           =   1215
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Speed"
         Height          =   375
         Index           =   4
         Left            =   7080
         TabIndex        =   31
         Top             =   2370
         Width           =   1215
      End
      Begin VB.TextBox txtSpeed 
         Height          =   315
         Left            =   4920
         TabIndex        =   30
         Text            =   "80.0"
         Top             =   2400
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Decel"
         Height          =   375
         Index           =   3
         Left            =   7080
         TabIndex        =   28
         Top             =   1830
         Visible         =   0   'False
         Width           =   1215
      End
      Begin VB.TextBox txtDecel 
         Height          =   315
         Left            =   4920
         TabIndex        =   27
         Text            =   "50.0"
         Top             =   1860
         Visible         =   0   'False
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Accel"
         Height          =   375
         Index           =   2
         Left            =   7080
         TabIndex        =   25
         Top             =   1290
         Visible         =   0   'False
         Width           =   1215
      End
      Begin VB.TextBox txtAccel 
         Height          =   315
         Left            =   4920
         TabIndex        =   24
         Text            =   "50.0"
         Top             =   1320
         Visible         =   0   'False
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Change"
         Height          =   375
         Index           =   1
         Left            =   7110
         TabIndex        =   22
         Top             =   750
         Width           =   1215
      End
      Begin VB.TextBox txtChange 
         Height          =   315
         Left            =   4920
         TabIndex        =   21
         Text            =   "1"
         Top             =   780
         Width           =   825
      End
      Begin VB.ComboBox cmbChange 
         Height          =   300
         ItemData        =   "Robot.frx":0101
         Left            =   2280
         List            =   "Robot.frx":010B
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   20
         Top             =   780
         Width           =   1125
      End
      Begin VB.CommandButton cmdRobCancel 
         Caption         =   "Cancel"
         Height          =   375
         Left            =   7080
         TabIndex        =   19
         Top             =   6270
         Width           =   1215
      End
      Begin VB.Timer Timer1 
         Left            =   7920
         Top             =   9090
      End
      Begin VB.ComboBox cmbVarType 
         Height          =   300
         ItemData        =   "Robot.frx":011B
         Left            =   4140
         List            =   "Robot.frx":0128
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   14
         Top             =   240
         Width           =   735
      End
      Begin VB.ComboBox cmbPath 
         Height          =   300
         ItemData        =   "Robot.frx":0135
         Left            =   3210
         List            =   "Robot.frx":0142
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   13
         Top             =   240
         Width           =   735
      End
      Begin VB.ComboBox cmbComp 
         Height          =   300
         ItemData        =   "Robot.frx":0151
         Left            =   2280
         List            =   "Robot.frx":015B
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   12
         Top             =   240
         Width           =   735
      End
      Begin VB.TextBox txtVarIndex 
         Height          =   315
         Left            =   4920
         TabIndex        =   4
         Text            =   "1"
         Top             =   240
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Go!"
         Height          =   375
         Index           =   0
         Left            =   7080
         TabIndex        =   5
         Top             =   210
         Width           =   1215
      End
      Begin VB.Label Label 
         Caption         =   ","
         Height          =   255
         Left            =   4920
         TabIndex        =   70
         Top             =   4680
         Width           =   135
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   10
         X1              =   1200
         X2              =   8280
         Y1              =   5520
         Y2              =   5520
      End
      Begin VB.Label Label8 
         Caption         =   "DEPART"
         Height          =   375
         Left            =   1200
         TabIndex        =   68
         Top             =   5730
         Width           =   5175
      End
      Begin VB.Label Label7 
         Caption         =   "APPROACH"
         Height          =   375
         Left            =   1200
         TabIndex        =   63
         Top             =   4680
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   9
         X1              =   1200
         X2              =   8280
         Y1              =   4440
         Y2              =   4440
      End
      Begin VB.Label Label6 
         Caption         =   ",V"
         Height          =   195
         Index           =   13
         Left            =   5970
         TabIndex        =   57
         Top             =   3570
         Width           =   195
      End
      Begin VB.Label Label6 
         Caption         =   ",V"
         Height          =   195
         Index           =   12
         Left            =   3720
         TabIndex        =   56
         Top             =   3570
         Width           =   195
      End
      Begin VB.Label Label6 
         Caption         =   ",V"
         Height          =   195
         Index           =   11
         Left            =   3030
         TabIndex        =   55
         Top             =   3570
         Width           =   195
      End
      Begin VB.Label Label6 
         Caption         =   "( V"
         Height          =   195
         Index           =   10
         Left            =   2220
         TabIndex        =   54
         Top             =   3570
         Width           =   255
      End
      Begin VB.Label Label6 
         Caption         =   "("
         Height          =   195
         Index           =   9
         Left            =   3940
         TabIndex        =   53
         Top             =   3000
         Width           =   105
      End
      Begin VB.Label Label6 
         Caption         =   ","
         Height          =   195
         Index           =   8
         Left            =   4830
         TabIndex        =   52
         Top             =   3000
         Width           =   75
      End
      Begin VB.Label Label6 
         Caption         =   "),"
         Height          =   195
         Index           =   7
         Left            =   4440
         TabIndex        =   51
         Top             =   3570
         Width           =   105
      End
      Begin VB.Label Label6 
         Caption         =   ")"
         Height          =   195
         Index           =   6
         Left            =   5790
         TabIndex        =   50
         Top             =   3000
         Width           =   105
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   7
         X1              =   1170
         X2              =   8280
         Y1              =   3390
         Y2              =   3390
      End
      Begin VB.Label Label6 
         Caption         =   " ROTATE"
         Height          =   225
         Index           =   5
         Left            =   1110
         TabIndex        =   42
         Top             =   3570
         Width           =   735
      End
      Begin VB.Label Label6 
         Caption         =   "DRIVEEx"
         Height          =   195
         Index           =   4
         Left            =   1170
         TabIndex        =   36
         Top             =   3000
         Width           =   735
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   6
         X1              =   1170
         X2              =   8280
         Y1              =   2820
         Y2              =   2820
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   5
         X1              =   1170
         X2              =   8280
         Y1              =   2280
         Y2              =   2280
      End
      Begin VB.Label Label6 
         Caption         =   "SPEED"
         Height          =   375
         Index           =   3
         Left            =   1170
         TabIndex        =   32
         Top             =   2460
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   4
         X1              =   1170
         X2              =   8280
         Y1              =   6120
         Y2              =   6120
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   3
         X1              =   1170
         X2              =   8280
         Y1              =   1740
         Y2              =   1740
      End
      Begin VB.Label Label6 
         Caption         =   "DECEL"
         Height          =   375
         Index           =   2
         Left            =   1170
         TabIndex        =   29
         Top             =   1920
         Visible         =   0   'False
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   2
         X1              =   1170
         X2              =   8280
         Y1              =   1200
         Y2              =   1200
      End
      Begin VB.Label Label6 
         Caption         =   "ACCEL"
         Height          =   375
         Index           =   1
         Left            =   1170
         TabIndex        =   26
         Top             =   1380
         Visible         =   0   'False
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   1
         X1              =   1170
         X2              =   8280
         Y1              =   660
         Y2              =   660
      End
      Begin VB.Label Label6 
         Caption         =   "CHANGE"
         Height          =   375
         Index           =   0
         Left            =   1170
         TabIndex        =   23
         Top             =   840
         Width           =   5175
      End
      Begin VB.Label lblPos 
         Caption         =   "P(?,?,?..)"
         Height          =   255
         Left            =   1320
         TabIndex        =   18
         Top             =   9270
         Width           =   6435
      End
      Begin VB.Label lblMoving 
         Caption         =   "?"
         Height          =   255
         Left            =   1290
         TabIndex        =   17
         Top             =   9000
         Width           =   1095
      End
      Begin VB.Label Label5 
         Caption         =   "Position :  "
         Height          =   195
         Left            =   420
         TabIndex        =   16
         Top             =   9300
         Width           =   885
      End
      Begin VB.Label Label1 
         Caption         =   "Moving :  "
         Height          =   225
         Left            =   420
         TabIndex        =   15
         Top             =   9000
         Width           =   885
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   0
         X1              =   150
         X2              =   8280
         Y1              =   8520
         Y2              =   8520
      End
      Begin VB.Label lblMove 
         Caption         =   "MOVE "
         Height          =   375
         Left            =   1170
         TabIndex        =   11
         Top             =   300
         Width           =   5175
      End
      Begin VB.Label Label4 
         Caption         =   "Robot Status : "
         Height          =   225
         Index           =   0
         Left            =   150
         TabIndex        =   10
         Top             =   8640
         Width           =   8055
      End
      Begin VB.Label Label3 
         Caption         =   "Command : "
         Height          =   255
         Index           =   0
         Left            =   150
         TabIndex        =   9
         Top             =   300
         Width           =   6765
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Connection"
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   8415
      Begin VB.CommandButton cmdConnect 
         Caption         =   "Connect"
         Height          =   375
         Left            =   5760
         TabIndex        =   2
         Top             =   300
         Width           =   1215
      End
      Begin VB.CommandButton cmdDisconnect 
         Caption         =   "Disconnect"
         Height          =   375
         Left            =   7080
         TabIndex        =   3
         Top             =   300
         Width           =   1215
      End
      Begin VB.ComboBox cmbParameter 
         Height          =   300
         Left            =   1320
         TabIndex        =   1
         Top             =   360
         Width           =   4365
      End
      Begin VB.Label Label2 
         Alignment       =   1  '右揃え
         Caption         =   "Parameter : "
         Height          =   255
         Left            =   240
         TabIndex        =   7
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.Label lblDebug 
      Height          =   285
      Left            =   180
      TabIndex        =   33
      Top             =   10920
      Width           =   7065
   End
End
Attribute VB_Name = "frmRobot"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private caoEng As New CaoEngine
Private caoCtrls As CaoControllers
Private WithEvents caoCtrl  As CaoController
Attribute caoCtrl.VB_VarHelpID = -1
Private caoRob  As CaoRobot
Private caoRobVar As CaoVariable
Private caoRobPos As CaoVariable

Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


' ----------------------------------------------------
Private Sub Form_Load()

    With cmbParameter
        .Clear
        .AddItem "192.168.0.1" ' <- Change this for your controller IP setting.
        .ListIndex = 0
    End With
    
    With cmbComp
        .Clear
        .AddItem "P,"
        .AddItem "L,"
        .ListIndex = 0
    End With
    
    With cmbPath
        .Clear
        .AddItem " "
        .AddItem "@P "
        .AddItem "@E "
        .ListIndex = 0
    End With
    
    With cmbVarType
        .Clear
        .AddItem "P"
        .AddItem "T"
        .AddItem "J"
        .ListIndex = 0
    End With
    
    With cmbChange
        .Clear
        .AddItem "TOOL"
        .AddItem "WORK"
        .ListIndex = 0
    End With
    
    txtVarIndex.Text = "1"
    
    With cmbDrvAt
        .Clear
        .AddItem " "
        .AddItem "@P "
        .AddItem "@E "
        .ListIndex = 0
    
        .ItemData(0) = 0
        .ItemData(1) = -1
        .ItemData(2) = -2
    End With
    With cmbJn
        .Clear
        .AddItem "1"
        .AddItem "2"
        .AddItem "3"
        .AddItem "4"
        .AddItem "5"
        .AddItem "6"
        .AddItem "7"
        .AddItem "8"
        .ListIndex = 0
    End With
    
    With cmbRotAt
        .Clear
        .AddItem " "
        .AddItem "@P "
        .AddItem "@E "
        .ListIndex = 0
    End With

    With cmbSuf
        .ListIndex = 0
    End With

    optSuf(0).Value = True
    
    With cmbApproachComp
        .ListIndex = 0
    End With
    
    With cmbApproachVarType
        .ListIndex = 0
    End With
    
    With cmbDepartComp
        .ListIndex = 0
    End With

    With Timer1
        .Enabled = False
        .Interval = 150
    End With
    
    cmdDisconnect_Click

    Set caoEng = New CaoEngine
    Set caoCtrls = caoEng.Workspaces(0).Controllers

End Sub

' ----------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)

    If Not cmdExit.Enabled Then GoTo CancelProc

    cmdDisconnect_Click
    
    Set caoCtrls = Nothing
    Set caoEng = Nothing

    Exit Sub

CancelProc:
    Cancel = True

End Sub

Private Sub cmdRobCancel_Click()
    caoRob.Halt 'for return from command locking mode
End Sub


' ----------------------------------------------------
Private Sub cmdConnect_Click()

    On Error GoTo ErrProc
    
    Dim sConn As String
    
    cmdDisconnect_Click
    
    sConn = "Server=" & cmbParameter.Text
    
    Set caoCtrl = caoCtrls.Add("RC1", "CaoProv.DENSO.RC8", "", sConn)
    
    Set caoRob = caoCtrl.AddRobot("RobSlave")
    
    Set caoRobVar = caoRob.AddVariable("@BUSY_STATUS")
    
    Set caoRobPos = caoRob.AddVariable("@CURRENT_POSITION")
        
    'Unlock all command buttons
    Dim i%
    For i = cmdRobMaster.LBound To cmdRobMaster.UBound
        cmdRobMaster(i).Enabled = True
    Next i
    cmdRobCancel.Enabled = True
    
    Timer1.Enabled = True
    
    Exit Sub
ErrProc:
    MsgBox Err.Description
    
End Sub

' ----------------------------------------------------
Private Sub cmdDisconnect_Click()

    'Lock all command buttons
    Dim i%
    For i = cmdRobMaster.LBound To cmdRobMaster.UBound
        cmdRobMaster(i).Enabled = False
    Next i
    cmdRobCancel.Enabled = False

    Timer1.Enabled = False

    If Not caoRobPos Is Nothing Then
        Set caoRobPos = Nothing
    End If

    If Not caoRobVar Is Nothing Then
        Set caoRobVar = Nothing
    End If

    If Not caoRob Is Nothing Then
        Set caoRob = Nothing
    End If

    If Not caoCtrl Is Nothing Then
        caoCtrls.Remove caoCtrl.Index
        Set caoCtrl = Nothing
    End If
    
End Sub

Private Sub cmdRobMaster_Click(Index As Integer)

    Dim i%
    Dim sOpt$
    
    'Lock all command buttons
    For i = cmdRobMaster.LBound To cmdRobMaster.UBound
        cmdRobMaster(i).Enabled = False
    Next i
    cmdConnect.Enabled = False
    cmdDisconnect.Enabled = False
    cmdExit.Enabled = False
    cmdRobCancel.Enabled = True

    On Error GoTo ErrProc

    caoRob.Execute "TakeArm", Array(0, 1)

    Select Case Index
    Case 0: 'MOVE
        caoRob.Move LLng(cmbComp.ListIndex + 1), cmbPath.Text & cmbVarType.Text & txtVarIndex.Text, "NEXT"
        
    Case 1: 'CHANGE
        caoRob.Change cmbChange.Text + txtChange.Text
        
    Case 2: 'ACCEL
'''''        caoRob.Accelerate LSng(-1), LSng(txtAccel.Text)

    Case 3: 'DECEL
'''''        caoRob.Accelerate LSng(-1), LSng(-1), LSng(txtDecel.Text)   '-1:Do not care

    Case 4: 'SPEED
        caoRob.Speed LSng(-1), LSng(txtSpeed.Text)
        
    Case 5: 'DRIVEEx
        caoRob.Execute "DriveEx", Array(cmbDrvAt.Text & "(" & LLng(cmbJn.ListIndex + 1) & "," & LSng(txtDrvDeg.Text) & ")", "NEXT")
        
    Case 6: 'ROTATE
        sOpt = Trim(cmbRotAt.Text)
        If Len(sOpt) > 0 Then
            sOpt = sOpt + ",NEXT"
        Else
            sOpt = ",NEXT"
        End If
        
        If (optSuf(0).Value) Then
            ' Vn1,Vn2,Vn3
            caoRob.Rotate "V" & txtV(0).Text & "," & "V" & txtV(1).Text & "," & "V" & txtV(2).Text, LSng(txtRotDeg.Text), "V" & txtV(3).Text, sOpt
        Else
            ' XY,YZ,ZX ...
            caoRob.Rotate cmbSuf.Text, LSng(txtRotDeg.Text), "V" & txtV(3).Text, sOpt
        End If
    
    Case 7: 'APPROACH
        caoRob.Execute "Approach", Array(cmbApproachComp.ItemData(cmbApproachComp.ListIndex), _
                                        cmbApproachVarType.List(cmbApproachVarType.ListIndex) & txtApproachVarIndex.Text, _
                                        cmbApproachPath.List(cmbApproachPath.ListIndex) & " " & txtApproach.Text, _
                                        "NEXT")
    Case 8: 'DEPART
        caoRob.Execute "Depart", Array(cmbDepartComp.ItemData(cmbDepartComp.ListIndex), _
                                        cmbDepartPath.List(cmbDepartPath.ListIndex) & " " & txtDepart.Text, _
                                        "NEXT")
    
    End Select
    
    'Wait until robot stops
    Do Until caoRob.Execute("MotionComplete")
        DoEvents
    Loop
    
    caoRob.Execute "GiveArm"
    
DoExit:
    'Unlock all command buttons
    For i = cmdRobMaster.LBound To cmdRobMaster.UBound
        cmdRobMaster(i).Enabled = True
    Next i
    cmdConnect.Enabled = True
    cmdDisconnect.Enabled = True
    cmdExit.Enabled = True
    cmdRobCancel.Enabled = True
    Exit Sub

ErrProc:
    caoRob.Execute "GiveArm"
    
    MsgBox Err.Description
    GoTo DoExit
    
End Sub


' ----------------------------------------------------
Private Sub cmdExit_Click()

    Unload Me
    
End Sub

Private Sub cmbSuf_Click()

    optSuf(0).Value = False
    optSuf(1).Value = True
    
End Sub


'Update Robot Status
Private Sub Timer1_Timer()

    'Moving = True / False
    If Not caoRobVar Is Nothing Then
        lblMoving.Caption = LStr(caoRobVar.Value)
    End If
    'Current Position
    If Not caoRobPos Is Nothing Then
        Dim vPos As Variant
        vPos = caoRobPos.Value
        
        Dim i%, imin%, imax%
        imin = LBound(vPos): imax = UBound(vPos)
        lblPos.Caption = "P( "
        For i = imin To imax - 1
            lblPos.Caption = lblPos.Caption + LStr(Format(vPos(i), "0.0#")) + ", "
        Next
        lblPos.Caption = lblPos.Caption + LStr(Format(vPos(imax), "0.0#")) + " )"
    End If
    
End Sub

'-----------------------------------------------------------
Public Function LLng(ByRef expression) As Long
    
    LLng = CLng(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LInt(ByRef expression) As Integer
    
    LInt = CInt(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LByte(ByRef expression) As Byte
    
    LByte = CByte(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LDbl(ByRef expression) As Double
    
    LDbl = CDbl(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LSng(ByRef expression) As Single
    
    LSng = CSng(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LBool(ByRef expression) As Boolean
    
    LBool = CBool(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LVar(ByRef expression) As Variant
    
    LVar = CVar(Val(expression))

End Function

'-----------------------------------------------------------
Public Function LStr(ByRef expression) As String
    
    On Error Resume Next
    
    LStr = expression
    LStr = LTrim$(Str(expression))

End Function


