Passwort-Abfrage mit Array

Option Base, Array
Option Base 1 Der Index beginnt mit 1, nicht mit Null.
Private namen(5) As String Das Array enthält 5 Namen.
Private Sub Form_Load()
  namen(1) = "Heinz"
  namen(2) = "Helga"
  namen(3) = "Micha"
  namen(4) = "Margot"
  namen(5) = "Anton"
 
  frmAnmeld.Show
  txtName.SetFocus
  txtPw.PasswordChar = "*"
End Sub
Private Sub cmdOK_Click()
Dim index As Byte
passwort = "cdi"
For index = 1 To 5
  If txtName.Text = namen(index) And txtPw.Text = passwort Then
    MsgBox "Hallo " & txtName.Text & "!", , "Anmeldung erfolgreich"
    frmAnmeld.Hide
    frmDatPruef.Show Bei korrekter Anmeldung wird ein weiteres Formular
  End If gestartet.
Next index
If txtName.Text = "" Or txtPw.Text <> passwort Then
  Select Case MsgBox("Anmeldung kann ohne Passwort-" & vbCrLf & _
    "eingabe nicht erfolgen!" & vbCrLf & "Noch ein Versuch?", 4 + 16, "Abbruch")
    Case 6: txtName.Text = ""
           txtPw.Text = ""
           cmdOK.Enabled = False
           txtName.SetFocus
    Case 7: Unload Me
  End Select
  Call versuche
End If
End Sub
Private Sub versuche()
Static max As Integer
max = max + 1
  If max >= 3 Then
    MsgBox "Keine weiteren Versuche mehr möglich!", 0 + 64, "Abbruch"
    Unload Me
  End If
End Sub
Private Sub txtPw_LostFocus()
  If txtName.Text = "" And txtPw.Text = "" Then
    cmdOK.Enabled = False
    txtName.SetFocus
  Else
    cmdOK.Enabled = True
    cmdOK.SetFocus
  End If
End Sub
Private Sub cmdEnde_Click()
  Unload frmAnmeld
  Unload frmDatPruef
End Sub
Private Sub txtName_GotFocus()
  txtName.Text = ""
End Sub
Private Sub txtPw_GotFocus()
  txtPw.Text = ""
End Sub
Private Sub cmdEnde_Click() Vom zweiten Formular ins erste zurückspringen
  frmDatPruef.Hide
  frmAnmeld.Show
  frmAnmeld.cmdOK.Enabled = False
  frmAnmeld.txtName.Text = ""
  frmAnmeld.txtPw.Text = ""
  frmAnmeld.txtName.SetFocus
End Sub

 Ranking-Hits zurück Sitemap
Designed by www.wbrnet.info