Option
Explicit
Private
Sub
CommandButton1_Click()
Dim
i
As
Integer
i = areTextboxesFilled
If
i
Then
MsgBox i * -1 &
"/3 Textboxen sind leer."
, vbExclamation
Exit
Sub
End
If
i = checkInput
If
i
Then
MsgBox i * -1 &
"/2 Werte in Textboxen sind falsch."
, vbExclamation
Exit
Sub
End
If
MsgBox
"Alles in Ordnung."
, vbInformation
End
Sub
Private
Function
areTextboxesFilled()
As
Integer
Dim
txt
As
Control
For
Each
txt
In
Me
.Controls
If
VBA.TypeName(txt) =
"TextBox"
Then
areTextboxesFilled = areTextboxesFilled +
CInt
(txt.Value = vbNullString)
End
If
Next
txt
End
Function
Private
Function
checkInput()
As
Integer
Dim
txt
As
Control
For
Each
txt
In
Me
.Controls
If
VBA.TypeName(txt) =
"TextBox"
Then
Select
Case
txt.Name
Case
"mail"
:
checkInput = checkInput +
CInt
(InStr(1, txt.Text,
"@"
, vbBinaryCompare) = 0)
Case
"web"
:
checkInput = checkInput +
CInt
(InStr(1, txt.Text,
"."
, vbBinaryCompare) = 0)
End
Select
End
If
Next
txt
End
Function