Wednesday, August 18, 2010

In visual basic 6, how can you search a record containing special characters?

i have a textbox and a datagrid control connected to ms access database table using the ADODC control. i want to search a record (i.e. by title) which ill type in the textbox. how can i search if the title has special characters like apostrophe (')? pls tell me the code/s . thanksIn visual basic 6, how can you search a record containing special characters?
this routine treats anything that is not an alpha-numeric character as ';special,'; including spaces, tabs, carriage returns, line feeds, etc. modify the code to explicitly reference anything you consider ';sepcial.';








Option Explicit


Dim msTitle As String








Private Sub Command1_Click()








Dim lsChar As String


Dim liChar As Integer


Dim li As Integer


Dim mBlnSpecial As Boolean





msTitle = Text1.Text





For li = 0 To Len(msTitle) - 1





lsChar = Mid(msTitle, li + 1, 1)





liChar = Asc(lsChar)











Select Case liChar





'--numbers


Case 48 To 57





'--lower case


Case 65 To 90





'--upper case


Case 97 To 122





Case Else





mBlnSpecial = True


Debug.Print (Asc(lsChar))








End Select














Next li








If mBlnSpecial = True Then





li = MsgBox(';There is at least one sepcial character.';, vbOKOnly, ';TEST';)











End If





End SubIn visual basic 6, how can you search a record containing special characters?
it's long cos i didn't clean up for extra returns. hadn't considered instr() at first - prolly wrote this when i was sleepy. glad it helped. i really don't understand what you're looking for - how is ';searching a record with apostrophe'; different from ';searching the occurrence of apostrophe?';

Report Abuse



You can ';escape'; the characters by putting a ' (a apostrophy) before like ('')

No comments:

Post a Comment