Visual Basic Tips


プロシジャ・コントロール型の判定


As Controlで定義される変数の型を判定するサンプルです。

Sub ControlType(ctl As Control)
  
If TypeOf ctl Is Menu Then
    
Debug.Print "メニューです     Name=" & ctl.Name
  
End If
  
If TypeOf ctl Is TextBox Then
    
Debug.Print "テキストボックスです Name=" & ctl.Name
  End If
  
If TypeOf ctl Is Label Then
    Debug.Print "ラベルです      Name=" & ctl.Name
  End If
  
If TypeOf ctl Is CommandButton Then
    
Debug.Print "コマンドボタンです  Name=" & ctl.Name
  
End If
  
If TypeOf ctl Is CheckBox Then
    
Debug.Print "チェックボックスです Name=" & ctl.Name
  End If
  
If TypeOf ctl Is OptionButton Then
    
Debug.Print "オプションボタンです Name=" & ctl.Name
  End If
  
If TypeOf ctl Is ComboBox Then
    
Debug.Print "コンボボックスです  Name=" & ctl.Name
  End If
  
If TypeOf ctl Is ListBox Then
    
Debug.Print "リストボックスです  Name=" & ctl.Name
  End If
End Sub


DownLoad vbtips117.lzh 2KB (VB6.0)