ユーザー名とパスワードのフィールドの下にある Access 2007 テーブルにレコードを保存しました。アクセステーブルからユーザー名とパスワードを検証するために、VB6テキストボックスに適切な大文字と小文字が入力されているかどうかを確認したいと思います。この点で私を助けてください。ありがとうございました
サルファラズ
ユーザー名とパスワードのフィールドの下にある Access 2007 テーブルにレコードを保存しました。アクセステーブルからユーザー名とパスワードを検証するために、VB6テキストボックスに適切な大文字と小文字が入力されているかどうかを確認したいと思います。この点で私を助けてください。ありがとうございました
サルファラズ
StrCompが適している可能性があります:
Sub TestMatch()
'string1 is less than string2 -1
'string1 is equal to string2 0
'string1 is greater than string2 1
'string1 or string2 is Null Null
Debug.Print StrComp("ABC", "AB", vbBinaryCompare) ''= 1
Debug.Print StrComp("ABC", "abc", vbBinaryCompare) ''= -1
Debug.Print StrComp("ABC", "ABC", vbBinaryCompare) ''= 0
Debug.Print StrComp(Null, "ABC", vbBinaryCompare) ''= Null
End Sub
私が実際に使用するものではなく、 RegExを使用するいくつかの投稿を取得する場合があるため、この関数は、2 つの文字列が一致し、大文字と小文字が区別されるかどうかを判断するのに役立ちます。
Public Function ExactMatch(varFirst As Variant, varSecond As Variant) As Boolean
Dim inti As Integer
'Initialise to False and amend to True if function passes
ExactMatch = False
'Initial checks before proceeding (Null?, Length mismatch?)
If IsNull(varFirst) And IsNull(varSecond) Then
ExactMatch = True
Exit Function
ElseIf IsNull(varFirst) And Not IsNull(varSecond) Then
Exit Function
ElseIf Not IsNull(varFirst) And IsNull(varSecond) Then
Exit Function
End If
If Len(CStr(varFirst)) <> Len(CStr(varSecond)) Then Exit Function
'Begin
For inti = 1 To Len(CStr(varFirst))
If Asc(Mid(varFirst, inti, 1)) <> Asc(Mid(varSecond, inti, 1)) Then Exit Function
Next
ExactMatch = True
End Function
私は最終的に答えを持っています:
Connection
Set rs = New ADODB.Recordset
Qry = "SELECT Password FROM Login WHERE UserName = '" & Text1.Text & "'"
rs.Open Qry, Con, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
If rs(0) = Text2.Text Then
msgbox"OK"
exit sub
Else
MsgBox "Invalid Username or Password", vbInformation, "Login..."
End If
Else
MsgBox "Invalid Username or Password", vbInformation, "Login..."
End If
コーディングを楽しむ
コードと関数を比較するあらゆる種類の派手な文字列を投げ込んでいる人を見かけます...私は困惑しています.2つの変数を比較するだけではどうですか?
変数は、ユーザーと変数によって入力strUserName_Entered
され、DB からロードされます。strPassword_Entered
strUserName_DB
strPassword_DB
If strUserName_Entered = strUserName_DB AND strPassword_Entered = strPassword_DB Then
' Everything is OK, entered username/password combination is exactly the same as the one from DB
Else
' Username/password combination do not match
End If
ユーザーが正しいユーザー名/パスワードを入力したときに区別したいが、大文字と小文字が間違っている場合は、これを使用できます
If strUserName_Entered = strUserName_DB AND strPassword_Entered = strPassword_DB Then
' Everything is OK, entered username/password combination is exactly the same as the one from DB
Else If UCase(strUserName_Entered) = UCase(strUserName_DB) AND UCase(strPassword_Entered) = UCase(strPassword_DB) Then
' Username/password combination match, but at least one or more characters is/are in a wrong case
Else
' Username/password combination do not match (not the case error)
End If