[RESOLVED] Check textbox contains capital letter
I would like to know how to check the string input by the user?If the user input capclock letter, the the messagebox pop up when i click the command button. I would like to pop up the with mesagebox when the user input the caplock letter "B B" or "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Re: Check textbox contains capital letter
vb Code:
Dim ValidStr As String
Private Sub Form_Load()
ValidStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
End Sub
Private Sub Text1_KeyPress( _
KeyAscii As Integer _
)
If InStr(ValidStr, ChrW(KeyAscii)) > 0 Then
MsgBox "Hello"
End If
End Sub
Re: Check textbox contains capital letter
Thank you. it work when user input. If prefer to check the code when use press the commad button. But how to check code?
Code:
Private Sub Command1_Click()
ValidStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
If InStr(ValidStr, ChrW(KeyAscii)) > 0 Then
MsgBox "Hello"
End If
End Sub
Re: Check textbox contains capital letter
Checking if a string contains capitals is easy...
Code:
If Text1.Text <> LCase$(Text1.Text) Then 'the textbox contains capitals
Depending on the situation it might be better to control the input to the Textbox so that it's always a particular case.
Re: Check textbox contains capital letter
Then check validstr against textbox.etxt instead of chrw(keyascii)
Re: Check textbox contains capital letter
vb Code:
Dim ValidStr As String
Private Sub Form_Load()
ValidStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
End Sub
Private Sub Command1_Click()
Dim i As Integer
Dim hasCaps As Boolean
For i = 1 To Len(Text1.Text)
If InStr(ValidStr, Mid$(Text1.Text, i, 1)) > 0 Then
hasCaps = True
Exit For
End If
Next
If hasCaps Then
MsgBox "Textbox contains capital letters."
End If
End Sub
Re: Check textbox contains capital letter
You can leave the
Code:
Private Sub Form_Load()
ValidStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
End Sub
in the Form_Load and use those changes in your Comand1_Click:
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim Check As String
For i = 1 To Len (ValidStr)
Check = Mid (ValidStr, i,1)
If InStr(ValidStr, Check) > 0 Then
MsgBox "Hello"
Exit Sub
End If
Next i
End Sub
Re: [RESOLVED] Check textbox contains capital letter
Code:
Private Sub Command1_Click()
If Text1.Text = UCase(Text1.Text) And Text1.Text Like "*[A-Z]*" Then
MsgBox "All letters are Uppercase"
ElseIf Text1.Text = LCase(Text1.Text) And Text1.Text Like "*[a-z]*" Then
MsgBox "All letters are Lowercase"
ElseIf Text1.Text Like "*[A-Za-z]*" Then
MsgBox "Letters are mixed Uppercase and Lowercase"
Else
MsgBox "No letter exist"
End If
End Sub
Re: [RESOLVED] Check textbox contains capital letter
Whats wrong with my one liner? It accounts for the full set of capitals which would include "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ 08;ÑÒÓÔÕÖÙÚÛÜÝ" in the UK.
Re: [RESOLVED] Check textbox contains capital letter
Quote:
Originally Posted by Milk
Whats wrong with my one liner? It accounts for the full set of capitals which would include "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝ" in the UK.
That is pretty good and should be the first choice for matrik02 :thumb:
Re: [RESOLVED] Check textbox contains capital letter
@matrik02,
If someone has helped you here or you find a solution yourself then you should say something instead of quietly mark the thread as resolved and go away.
You still have many other questions you want to have answers.
Re: [RESOLVED] Check textbox contains capital letter
Thank you to all of you.
I used thread number #4 and #2