コンテンツにスキップ
サンプルプログラム > DiBit >

Visual Basic 6.0

開発環境の設定

  1. Ydx.bas をプロジェクトフォルダにコピーします。

  2. Ydx.bas をプロジェクトに追加します。

コントロール

変数

Dim id As Long
Dim result As Long

実行結果の表示

Private Sub ResultShow(ByVal title As String, ByVal resultCode As Long)
    Dim resultString As String
    Call YdxCnvResultToString(resultCode, resultString)
    Select Case resultCode
        Case 0, Ydx.YDX_RESULT_DI_EXCEED_DATA_NUM, Ydx.YDX_RESULT_DI_EXCEED_BUF_SIZ
            MsgBox resultString, vbInformation, title
        Case Else
            MsgBox resultString, vbCritical, title
    End Select
End Sub

フォームロード

Private Sub Form_Load()
    ' ユニット識別スイッチ
    cboUnitSwitch.AddItem "0"
    cboUnitSwitch.AddItem "1"
    cboUnitSwitch.AddItem "2"
    cboUnitSwitch.AddItem "3"
    cboUnitSwitch.AddItem "4"
    cboUnitSwitch.AddItem "5"
    cboUnitSwitch.AddItem "6"
    cboUnitSwitch.AddItem "7"
    cboUnitSwitch.AddItem "8"
    cboUnitSwitch.AddItem "9"
    cboUnitSwitch.AddItem "A"
    cboUnitSwitch.AddItem "B"
    cboUnitSwitch.AddItem "C"
    cboUnitSwitch.AddItem "D"
    cboUnitSwitch.AddItem "E"
    cboUnitSwitch.AddItem "F"
    cboUnitSwitch.ListIndex = 0

    ' 型名
    cboModelName.AddItem "DIO-16/16C-USC"
    cboModelName.AddItem "DIO-16/16D-UBC"
    cboModelName.AddItem "DIO-16/16D-USC"
    cboModelName.ListIndex = 0

    ' 入力チャネル
    cboInputChannel.AddItem "0"
    cboInputChannel.AddItem "1"
    cboInputChannel.AddItem "2"
    cboInputChannel.AddItem "3"
    cboInputChannel.AddItem "4"
    cboInputChannel.AddItem "5"
    cboInputChannel.AddItem "6"
    cboInputChannel.AddItem "7"
    cboInputChannel.AddItem "8"
    cboInputChannel.AddItem "9"
    cboInputChannel.AddItem "10"
    cboInputChannel.AddItem "11"
    cboInputChannel.AddItem "12"
    cboInputChannel.AddItem "13"
    cboInputChannel.AddItem "14"
    cboInputChannel.AddItem "15"
    cboInputChannel.ListIndex = 0

    ' 出力チャネル
    cboOutputChannel.AddItem "0"
    cboOutputChannel.AddItem "1"
    cboOutputChannel.AddItem "2"
    cboOutputChannel.AddItem "3"
    cboOutputChannel.AddItem "4"
    cboOutputChannel.AddItem "5"
    cboOutputChannel.AddItem "6"
    cboOutputChannel.AddItem "7"
    cboOutputChannel.AddItem "8"
    cboOutputChannel.AddItem "9"
    cboOutputChannel.AddItem "10"
    cboOutputChannel.AddItem "11"
    cboOutputChannel.AddItem "12"
    cboOutputChannel.AddItem "13"
    cboOutputChannel.AddItem "14"
    cboOutputChannel.AddItem "15"
    cboOutputChannel.ListIndex = 0

    ' 出力データ
    cboOutputData.AddItem "0"
    cboOutputData.AddItem "1"
    cboOutputData.ListIndex = 0
End Sub

オープン

Private Sub cmdOpen_Click()
    result = YdxOpen(cboUnitSwitch.ListIndex, cboModelName.Text, 0, id)
    If result <> 0 Then
        Call ResultShow("YdxOpen", result)
    Else
        cboUnitSwitch.Enabled = False
        cboModelName.Enabled = False
        Call ResultShow("オープン", result)
    End If
End Sub

入力

Private Sub cmdInput_Click()
    Dim data(0) As Long
    result = YdxDiInputBit(id, cboInputChannel.ListIndex, 1, 0, data(0))
    If result <> 0 Then
        Call ResultShow("YdxDiInputBit", result)
    Else
        MsgBox "データ : " & data(0), vbInformation, "入力"
    End If
End Sub

出力

Private Sub cmdOutput_Click()
    Dim data(0) As Long
    data(0) = cboOutputData.ListIndex
    result = YdxDoOutputBit(id, cboOutputChannel.ListIndex, 1, data(0))
    Call ResultShow("出力", result)
End Sub

クローズ

Private Sub cmdClose_Click()
    cboUnitSwitch.Enabled = True
    cboModelName.Enabled = True
    result = YdxClose(id)
    If result <> 0 Then
        Call ResultShow("YdxClose", result)
    Else
        Call ResultShow("クローズ", result)
    End If
End Sub

フォームアンロード

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    result = YdxClose(id)
    If result <> 0 And result <> YDX_RESULT_NOT_OPEN Then
        Call ResultShow("YdxClose", result)
    End If
End Sub