あなたはそれを
を処理する前に好き入力検証が必要
Option Explicit
Private Sub CommandButton1_Click()
Dim num As Long, tb1Val As Long, tb2Val As Long
Const DEFNUM As Long = 1 '<--| define a default value for 'num'
If Not ValidateInput(tb1Val, tb2Val) Then Exit Sub '<--| exit if textboxes have improper input
num = Application.InputBox("enter num", , DEFNUM, Type:=1) '<-_| 'Type:=1' forces a number input
With Me
If tb1Val * num > tb2Val.Value Then
MsgBox "textbox1 is higher"
Else
MsgBox "textbox2 is higher"
End If
End With
End Sub
Function ValidateInput(tb1Val As Long, tb2Val As Long) As Boolean
With Me
If IsNumber(.TextBox1) And IsNumber(.TextBox2) Then
tb1Val = CLng(.TextBox1.Value)
tb2Val = CLng(.TextBox2.Value)
ValidateInput = True
Else
MsgBox "Improper textbox input, try again", vbCritical
End If
End With
End Function
を次の
あなたが見ることができるように:
がFunction ValidateInput()
に求め
がしたいことがあり、関連するuserfom入力の検証は、あなたの実際のニーズに合わせてそれを変更する
はApplication.InputBox()
機能の代わりVBA.InputBox()
を使用しましたそのType
パラメータを利用して、入力を強制的に数字にします。
は、私はあなたが、これは、...ちょうどType conversion function(CDbl()
、CInt()
対応して必要なデータ型(Double
、Integer
、...)とCLng()
を持つすべてのLong
出現箇所を変更する場合であってはならない、Long
番号を必要とすると仮定
の代わりに
Val(TextBox1.Value)
を使用していたことを意味する、あなたは右、2 'TextBox'sと' InputBox'を比較しようとしていますか?その場合は、私の答えは –