Private Sub UserForm_Initialize()
'入力した数値を隠す設定
TextBox1.PasswordChar = "*"
Dim myFlag(0 To 9) As Boolean
Dim RndNo As Long
Randomize
For i = 1 To 10 'コマンドボタン分の数を指定します。
Do
RndNo = Int(Rnd * 10) '今回は0~9のランダムな数値を取得するのでこれでOKです。
Loop Until myFlag(RndNo) = False '配列をみて使われた数値かを判断します。
Controls("CommandButton" & i).Caption = RndNo
myFlag(RndNo) = True
Next i
End Sub
'ここから下はテキストボックスにボタンのCaptionの数値を入力する処理
Private Sub CommandButton1_Click()
TextBox1.Value = TextBox1.Value & CommandButton1.Caption
End Sub
Private Sub CommandButton2_Click()
TextBox1.Value = TextBox1.Value & CommandButton2.Caption
End Sub
Private Sub CommandButton3_Click()
TextBox1.Value = TextBox1.Value & CommandButton3.Caption
End Sub
Private Sub CommandButton4_Click()
TextBox1.Value = TextBox1.Value & CommandButton4.Caption
End Sub
Private Sub CommandButton5_Click()
TextBox1.Value = TextBox1.Value & CommandButton5.Caption
End Sub
Private Sub CommandButton6_Click()
TextBox1.Value = TextBox1.Value & CommandButton6.Caption
End Sub
Private Sub CommandButton7_Click()
TextBox1.Value = TextBox1.Value & CommandButton7.Caption
End Sub
Private Sub CommandButton8_Click()
TextBox1.Value = TextBox1.Value & CommandButton8.Caption
End Sub
Private Sub CommandButton9_Click()
TextBox1.Value = TextBox1.Value & CommandButton9.Caption
End Sub
Private Sub CommandButton10_Click()
TextBox1.Value = TextBox1.Value & CommandButton10.Caption
End Sub
コメントを残す