次の方法で共有


Value プロパティの使用例 (VJ++)

次の例では、選択したコントロールの Value プロパティを表示することで、さまざまな種類のコントロールに含めることができる を示します。

ユーザーは Tab キーを押すか、コントロールをクリックしてコントロールを選択します。 Depending on the type of control, the user can also specify a value for the control by typing in the text area of the control, by clicking one or more times on the control, or by selecting an item, page, or tab within the control. ユーザーは、適切なラベルが付いた CommandButton をクリックすることで、選択したコントロールの値を表示できます。

この例を使用するには、以下のサンプル コードをフォームの宣言部分にコピーします。 フォームに次が含まれていることを確認してください。

  • CommandButton1 と命名された CommandButton
  • テキスト ボックス ( TextBox ) コントロール (TextBox1)
  • チェック ボックス ( CheckBox ) コントロール (CheckBox1)
  • コンボ ボックス ( ComboBox ) コントロール (ComboBox1)
  • CommandButton2 と命名された CommandButton
  • リスト ボックス ( ListBox ) コントロール (ListBox1)
  • マルチ ページ ( MultiPage ) コントロール (MultiPage1)
  • 2 つのオプション ボタン ( OptionButton ) コントロール (OptionButton1 と OptionButton2)
  • ScrollBar1 と命名された ScrollBar
  • SpinButton1 と命名された SpinButton
  • タブ ストリップ ( TabStrip ) コントロール (TabStrip1)
  • TextBox2 と命名された TextBox
  • トグル ボタン ( ToggleButton ) コントロール (ToggleButton1)
Dim i As Integer 
 
Private Sub CommandButton1_Click() 
 TextBox1.Text = "Value of " & ActiveControl.Name _ 
 & " is " & ActiveControl.Value 
End Sub 
 
Private Sub UserForm_Initialize() 
 CommandButton1.Caption = "Get value of " _ 
 & "current control" 
 CommandButton1.AutoSize = True 
 CommandButton1.TakeFocusOnClick = False 
 CommandButton1.TabStop = False 
 
 TextBox1.AutoSize = True 
 
 For i = 0 To 10 
 ComboBox1.AddItem "Choice " & (i + 1) 
 ListBox1.AddItem "Selection " & (100 - i) 
 Next i 
 
 CheckBox1.TripleState = True 
 ToggleButton1.TripleState = True 
 
 TextBox2.Text = "Enter text here." 
End Sub

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。