k_fish

New Member
Joined
Nov 26, 2014
Messages
2
I am writing a Program with Visual Basic Editor which needs to have a Form (which has been created) with a password textbox and a Confirm Password Textbox. What I need is the program to check to see if the passwords are the same, any ideas on how to do it?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
The strComp function compares two strings, i.e,
Rich (BB code):
   '==========
   'test01
   '==========
   If Not StrComp(Me.TestBox1.Value, Me.TestBox2.Value, vbTextCompare) Then
      MsgBox "Test01 passwords don't match!"
   Else
      MsgBox "Test01 success"
   End If

You need read up on strComp. I can't remember if strComp is case sensitive or if allows special characters, i.e., period, hyphen, etc. The help file wasn't, you know, helpful.

An alternative approach would be to loop through the two string comparing the ASCII value of each character:
Rich (BB code):
   '=======
   'test02
   '========
   pwd01 = Me.TestBox1.Value
   pwd02 = Me.TestBox2.Value
   For i = 1 To Len(pwd01)
      If Asc(Mid(pwd01, i, 1)) <> Asc(Mid(pwd02, i, 1)) Then
         
         'Me.txtPwd01.Value = ""
         'Me.txtPwd02.Value = ""
         
         MsgBox "Test02 passwords don't match!"
         Exit Sub
      End If
   Next i
   MsgBox "Test02 success"

Hope this helps,
Bertie

[EDIT]
If you use Test02 you may need to compare the string lengths:
Len(pwd01) = Len(pwd02)

before the loop starts.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top