0

ユーザーが自分の「組み合わせ」を入力ボックスに入力するときに、少なくとも5文字でなければならないことを確認するにはどうすればよいですか?

これは私がこれまでに持っているコードです:

If (tboxStatus.Text) = "Combination Not Set" Or (tboxStatus.Text) = "UnLocked" Then
  Combination = CInt(InputBox("Set the Combination First"))
  tboxStatus.Text = "Locked"
ElseIf (tboxStatus.Text) = "Locked" Then
  MsgBox("You must first UnLock the safe before trying to change the combination.")
End If
4

2 に答える 2

1

手始めに...

Dim value as String = InputBox("Set the Combination First")
If (value.Trim.Length < 5) Then
    MsgBox ("Combination must be at least 5 characters")
Else
    Combination = CInt(value)
End If

特に、CInt() を実行する前に数値かどうかを確認する必要があります。

于 2013-03-21T21:25:26.707 に答える
0
If tboxStatus.Text = "Combination Not Set" OrElse tboxStatus.Text = "UnLocked" Then
    Dim result As String = ""

    While String.IsNullOrWhiteSpace(result) OrElse Not Integer.TryParse(result, Combination)
       result= InputBox("Set a Combination Number First")
    End While

    tboxStatus.Text = "Locked"

ElseIf tboxStatus.Text = "Locked" Then
    MsgBox("You must first UnLock the safe before trying to change the combination.")
End If
于 2013-03-21T21:34:31.713 に答える