|
-
May 16th, 2003, 04:51 PM
#1
Thread Starter
Frenzied Member
Using KeyPress to compare KeyAscii Values
Need assistance in using the KeyPress Sub to translate a Carriage Return and a Space into a different character.
What I am trying to accomplish is when a person hits Carriage Return in a text field, it converts it into \n and when they hit space it converts it into _ .
I understand I need to use
Private Sub Form_KeyPress (KeyAscii as Integer)
If KeyAscii = Asc (13) (I assume this is right for a CR?)
Then KeyAscii = Asc (92) & Asc (110) (Hoping this produces a \n)
But for some reason, it wont recognize Asc (13) as a carriage return. I even tried Asc ("13") but that doesnt seem to work either.
Any help would be appreciated.
-
May 16th, 2003, 05:12 PM
#2
Asc() returns an integer from the first character in the string.
VB Code:
Select Case KeyAscii
Case vbKeyReturn
KeyAscii = vbNewline
Case vbKeySpace
KeyAscii = Asc("_")
Case Else
EndSelect
-
May 16th, 2003, 05:18 PM
#3
The KeyAscii paramter already contains the ansi value for the keystroke, there is no reason for the conversion.
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text1.SelText = "\n"
KeyAscii = 0
End If
End Sub
-
May 16th, 2003, 06:02 PM
#4
Thread Starter
Frenzied Member
Thanks to both of you, worked like a charm.
-
May 26th, 2003, 01:12 PM
#5
Thread Starter
Frenzied Member
One other question I have, if I want to write a Quote, how would I go about entering that?
I have a API call to write keys and strings to an .ini file, but one entry needs to have quotes around it, like "entry".
So my current code is:
API_WritePrivateProfileString("Engine.R6MissionDescription", "m_AudioBankName", Text12.Text, spath2)
I need the text in text12.text to have quotes around it when I write it.
-
May 26th, 2003, 03:17 PM
#6
-
May 26th, 2003, 03:23 PM
#7
I assume you do not want to have the quotes appear in the TextBox. To include quotes in a string you need to double them up. Its best to use a constant, makes your code easier to read
VB Code:
Public Const Double_Quotes As String = """"
Dim strData As String
strData = Double_Quotes & Text12.Text & Double_Quotes
API_WritePrivateProfileString("Engine.R6MissionDescription", "m_AudioBankName", strData,spath2)
-
May 26th, 2003, 05:52 PM
#8
Thread Starter
Frenzied Member
Fantastic, thanks again guys.
-
May 27th, 2003, 08:05 AM
#9
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
|