VERSION 5.00
Begin VB.Form frmVariable 
   Caption         =   "Variable"
   ClientHeight    =   2295
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   2295
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows の既定値
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      Height          =   255
      Left            =   3600
      TabIndex        =   10
      Top             =   1920
      Width           =   975
   End
   Begin VB.CommandButton cmdGetValue 
      Caption         =   "Get"
      Height          =   255
      Left            =   3840
      TabIndex        =   9
      Top             =   1560
      Width           =   735
   End
   Begin VB.TextBox txtValue 
      Height          =   270
      Left            =   1080
      TabIndex        =   8
      Top             =   1560
      Width           =   2685
   End
   Begin VB.Frame Frame1 
      Caption         =   "Connect"
      Height          =   1335
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   4455
      Begin VB.CommandButton cmdDisconnect 
         Caption         =   "Disconnect"
         Height          =   255
         Left            =   3000
         TabIndex        =   6
         Top             =   960
         Width           =   1335
      End
      Begin VB.CommandButton cmdConnect 
         Caption         =   "Connect"
         Height          =   255
         Left            =   1560
         TabIndex        =   5
         Top             =   960
         Width           =   1335
      End
      Begin VB.TextBox txtCtrlName 
         Height          =   270
         Left            =   1920
         TabIndex        =   4
         Text            =   "RC1"
         Top             =   240
         Width           =   2415
      End
      Begin VB.TextBox txtVarName 
         Height          =   270
         Left            =   1920
         TabIndex        =   2
         Text            =   "I11"
         Top             =   600
         Width           =   2415
      End
      Begin VB.Label Label2 
         Alignment       =   1  '右揃え
         Caption         =   "Controller Name : "
         Height          =   255
         Left            =   120
         TabIndex        =   3
         Top             =   240
         Width           =   1695
      End
      Begin VB.Label Label1 
         Alignment       =   1  '右揃え
         Caption         =   "Variable Name : "
         Height          =   255
         Left            =   120
         TabIndex        =   1
         Top             =   600
         Width           =   1695
      End
   End
   Begin VB.Label Label3 
      Alignment       =   1  '右揃え
      Caption         =   "Value : "
      Height          =   255
      Left            =   120
      TabIndex        =   7
      Top             =   1560
      Width           =   855
   End
End
Attribute VB_Name = "frmVariable"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private caoEng As CaoEngine
Private caoCtrls As CaoControllers
Private caoCtrl As CaoController
Private caoVar As CaoVariable

' フォームロード
Private Sub Form_Load()

    ' CAOエンジン生成
    Set caoEng = New CaoEngine
    
    'コントローラコレクションの取得
    Set caoCtrls = caoEng.Workspaces(0).Controllers
End Sub

Private Sub Form_Unload(Cancel As Integer)

    ' コントローラの切断
    cmdDisconnect_Click
    
    ' CAOオブジェクトの解放
    Set caoCtrls = Nothing
    Set caoEng = Nothing
End Sub

' 接続処理
Private Sub cmdConnect_Click()
On Error GoTo ErrProc

    ' 現在接続済みのコントローラを解放
    cmdDisconnect_Click
    
    ' コントローラに接続
    Set caoCtrl = caoCtrls.Add(txtCtrlName, "CaoProv.CAP", "", "Provider=CaoProv.Dummy")
    
    ' 変数オブジェクト取得
    Set caoVar = caoCtrl.AddVariable(txtVarName)
        
    Exit Sub

ErrProc:
    cmdDisconnect_Click
    MsgBox Err.Description
End Sub

' 切断処理
Private Sub cmdDisconnect_Click()
    
    ' 変数オブジェクトの解放
    If Not caoVar Is Nothing Then
        Set caoVar = Nothing
    End If
   
    ' コントローラオブジェクトの解放
    If Not caoCtrl Is Nothing Then
        caoCtrls.Remove caoCtrl.Name
        Set caoCtrl = Nothing
    End If

End Sub

' Exitボタン
Private Sub cmdExit_Click()
    Unload Me
End Sub

' 値取得
Private Sub cmdGetValue_Click()
On Error GoTo ErrProc

    txtValue.Text = caoVar
    Exit Sub

ErrProc:
    MsgBox Err.Description
End Sub

' 値設定
Private Sub cmdPutValue_Click()
On Error GoTo ErrProc

    caoVar = txtValue.Text
    Exit Sub

ErrProc:
    MsgBox Err.Description
End Sub
