|
-
Apr 28th, 2008, 04:28 AM
#1
Thread Starter
Frenzied Member
[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"
-
Apr 28th, 2008, 04:38 AM
#2
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
-
Apr 28th, 2008, 05:02 AM
#3
Thread Starter
Frenzied Member
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
-
Apr 28th, 2008, 05:09 AM
#4
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.
-
Apr 28th, 2008, 05:10 AM
#5
Re: Check textbox contains capital letter
Then check validstr against textbox.etxt instead of chrw(keyascii)
-
Apr 28th, 2008, 05:11 AM
#6
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
-
Apr 28th, 2008, 05:17 AM
#7
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
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Apr 28th, 2008, 05:22 AM
#8
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
Last edited by anhn; Apr 28th, 2008 at 05:27 AM.
-
Apr 28th, 2008, 05:23 AM
#9
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.
-
Apr 28th, 2008, 05:33 AM
#10
Re: [RESOLVED] Check textbox contains capital letter
 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
-
Apr 28th, 2008, 05:52 AM
#11
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.
-
Apr 28th, 2008, 05:57 AM
#12
Thread Starter
Frenzied Member
Re: [RESOLVED] Check textbox contains capital letter
Thank you to all of you.
I used thread number #4 and #2
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|