[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

InStr Function (Single and Double Quotes)

This is what I'm using to check for the charactor ( - ). I need code to check for all the following charactors: Single Quote ' and Double Quote " and the dash - . Could someone help?

Check4Charactor = Trim$(Me.textBoxes(2).Text)

MyPos = InStr(1, Check4Charactor, "-")

If MyPos = True Then
 MsgBox "Avoid using ' - ' in your user name."
 Me.textBoxes(2).SetFocus
Exit Sub
End If

Thanks - ADawn
0
ADawn
Asked:
ADawn
1 Solution
 
appariCommented:
try
MyPos = InStr(1, Check4Charactor, "-") or InStr(1, Check4Charactor, "'") or InStr(1, Check4Charactor, """")

to check if atleast oneof the characters exists and if want to check for existance of all the characters use

MyPos = InStr(1, Check4Charactor, "-") and InStr(1, Check4Charactor, "'") and InStr(1, Check4Charactor, """")
0
 
arbertCommented:
Why don't you code something in the key_down event that checks for those characters and warn them right when they enter the character.....

Brett
0
 
clanglCommented:
Try using the ascii representation like this InStr(1, Check4Charactor, Chr(Ascii Representation for whatever special character you need)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
kevmeistCommented:
With

Public Const gblstrDefault_Doctor = "K. 'Hong, M.D."


Dim a As Integer

a = InStr(gblstrDefault_Doctor, "'")

After executing the above instruction, a returns a value of 4.
0
 
FunkyMeisterCommented:
For your textbox:

At the top of your code

Private Const BadKeys = Chr(34)+"'-" ' Quote = CHR(34)



Private Sub textbox_KeyPress(KeyAscii As Integer)
 If Instr(BadKeys,Chr(KeyAscii)) Then KeyAscii = 0
End Sub

Snacks on the key if it's bad.  Since KeyAscii isn't being ByVal'ed, you're hitting the actual Ascii code that'll wind up going to the input window.  Effectively, you're killing the keys form working in that textbox
0
 
itcprogCommented:
Try this little function.

Public Function CheckBadChar(strSourceString as String)
CheckBadChar = True 'Disallow by Default to be on the safe side.

if instr(strSourceString,"-") <> 0 then exit function 'Check for Minus
if instr(strSourceString,chr(34)) <> 0 then exit function 'Check for Double Quote
if instr(strSourceString,"'") <> 0 then exit function 'Check for Single Quote

'Add more here if you need them.

CheckBadChar = False

End Function

Then to use it simply do this.

If CheckBadChar(Check4Charactor) then
 MsgBox "Avoid using ' - ' in your user name."
 Me.textBoxes(2).SetFocus
 Exit Sub
end if ' or you could use else or whatever.
0
 
itcprogCommented:
Or alternatively just change the following line in your code to the new one.

Original:
If MyPos = True Then

To:
If MyPos <> 0 Then
0
 
CleanupPingCommented:
Hi ADawn,
This old question (QID 20559580) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Accept FunkyMeister's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now