6 Replies - 2093 Views - Last Post: 11 December 2012 - 02:16 AM Rate Topic: -----

#1 tbzserge  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 26-January 11

Check if small letter exists in textbox VB6

Posted 05 December 2012 - 08:13 AM

Hi,

I would like to check if small capital letter exist in textbox when pressing enter.

If it detects small letter in the textbox, it should prompt out some message.

As usual, i try to use KeyDown function for the enter.
I plan to use KeyAscii to help me on the checking, but it seemed that i couldn't do it in KeyDown function there.

Any better way else to help me on this?
Any help would be much appreciated. Thanks

This post has been edited by tbzserge: 05 December 2012 - 08:14 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Check if small letter exists in textbox VB6

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,778
  • Joined: 26-March 09

Re: Check if small letter exists in textbox VB6

Posted 05 December 2012 - 08:37 AM

You can use the ASC function to check your string for lower case letters, but you would need a loop to look at each individual letter and check whether it was in the ASCII range for lower case letters.

Alternatively, you could look at using regular expressions (Google for more information). It might seem a little complex initially, but they are quite powerful.

Have a try at one of them and post back with your code if you're still having problems.
Was This Post Helpful? 0
  • +
  • -

#3 tbzserge  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 26-January 11

Re: Check if small letter exists in textbox VB6

Posted 05 December 2012 - 07:30 PM

Hi, thanks for the reply.

I have thought another method too. But it doesn't look likea good solution afterall.

Private Sub text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then

Dim intInputLen As Integer
Dim intX As Integer

intInputLen = Len(Text1.Text)
For intX = 1 To intInputLen
Select Case Mid$(Text1.Text, intX, 1)
Case "a" To "z"
MsgBox "You have entered small letter"
Exit For
Case Else
MsgBox "Pass!"
End Select
Next
End If
End Sub




I want it will check every character that i enter, but not looping to repeat the process again if the condition is correct.
For my case, i will get msgbox pass 4 times if i enter XXXXdS.

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Check if small letter exists in textbox VB6

Posted 05 December 2012 - 11:38 PM

You had me going there, talking about "small capital" letters. You mean lowercase letters. Don't use keydown for this, use keypress. Keydown maps to the keys themselves, so for example the "1" on the keypad is different from the "1" in the top left corner of the keyboard. Keypress returns the ascii value of the key pressed in the KeyAscii argument. So all you have to do is check the keyascii value.

Also, you don't have to check the length of the string and/or use the Mid function. The "Key" events always only have one character, because they fire every time you press a key.

Simplify. :)

This post has been edited by BobRodes: 05 December 2012 - 11:41 PM

Was This Post Helpful? 0
  • +
  • -

#5 tbzserge  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 26-January 11

Re: Check if small letter exists in textbox VB6

Posted 06 December 2012 - 01:08 AM

Hi Bob,

Actually my scenario is like this,

The user is using scanner scanning the barcode data on textbox. So, it will come out a chunk of data like part number TPL112232.
If the data they scan accidentally contain lower case letter like tpl112232, the application should be able to check the strings inside the textbox and prompt out message if lower case is detected.
Do you think this can be done?

And yes, i do know the key press and Ascii key work. The fact is the user is using a scanner (with auto-enter configured in it). So, that's where i was thinking using keydown.

Any ideas about this? Thanks.
Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Check if small letter exists in textbox VB6

Posted 06 December 2012 - 10:58 PM

Why don't you just force the characters to upper case? UCase("tpl112232") = "TPL112232"
Was This Post Helpful? 0
  • +
  • -

#7 tbzserge  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 26-January 11

Re: Check if small letter exists in textbox VB6

Posted 11 December 2012 - 02:16 AM

Hi Bob,

The customer requires the prompt message.

Anyway, i have found my way to do it.

'occur after pressing enter
Dim intInputLen As Integer
Dim intX As Integer
Dim a As Boolean
a = False


intInputLen = Len(Text1.Text)
For intX = 1 To intInputLen
Select Case Mid$(Text1.Text, intX, 1)
Case "a" To "z"
a = True
Exit For
End Select
Next

If a = True Then
MsgBox "You have entered small letter"
End If




Thanks for the help.Really appreciate.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1