PasswProtect




Option Explicit
Dim Password As String
Dim CursorPositionAs Long
Dim NumCharsSelected As Long

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
'put password in textbox

Text1 = Password
'reset textbox state to what it was

Text1.SelStart = CursorPosition
Text1.SelLength = NumCharsSelected
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 8 Or KeyCode >= 32 Then 'Backspace or Printable
'save textbox contents

Password = Text1
'just to see whats there - remove Label1 in real life

Label1 = Password
'save textbox state

CursorPosition = Text1.SelStart
NumCharsSelected = Text1.SelLength
'obscure password in textbox

Text1 = String$(Len(Password), Text1.PasswordChar)
'reset textbox state to what it was

Text1.SelStart = CursorPosition
Text1.SelLength = NumCharsSelected
End If
End Sub











( passwprotect.html )- by Paolo Puglisi - Modifica del 17/12/2023