|
-
Sep 7th, 2000, 06:17 AM
#1
Thread Starter
Member
I was told that this would work to kill the processing of a tab key when it is pressed:
private sub text1_KeyDown (shift as integer, keycode as integer)
if keycode = 9 then 'tab key
keycode = 0
end if
end sub
It does not work however. Is there any way to kill it without sending a backspace or anything like that? I'm trying to make my tabs in a multiline text box 4 spaces instead of 8, but the tab is still sent after I send the four spaces. Any help will be rewarded with profuse thanks.
-
Sep 7th, 2000, 06:26 AM
#2
_______
<?>
Code:
'You can set the Tabstop property to false for all the controls:
'disable the tab form
Private Sub Form_Load()
Dim i As Integer
On Error Resume Next
For i = 0 To Controls.Count - 1 ' Use the Controls collection
Controls(i).TabStop = False
Next
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 7th, 2000, 06:44 AM
#3
Thread Starter
Member
Not Quite what I'm asking...
I don't want to kill the tabstop, just the processing of a tab in the textbox. Tab doesn't change controls as it is, but it does insert 8 spaces. OnKeyDown, I would like to kill the tab and insert 4 spaces instead but I don't know how to kill the tab after I have captured it or any key for that matter. A similar example would be inserting "b" when the "a" key is pressed without sending a backspace to delete the a. I don't want the "a" to appear at all.
-
Sep 7th, 2000, 07:26 AM
#4
transcendental analytic
try returning the focus to the textbox with textboxname.setfocus
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 7th, 2000, 07:42 AM
#5
Thread Starter
Member
Still not it...
Apparently more background is needed. My main form is one huge textbox used for text editing. When the person hits tab at this point, 8 spaces are entered into the textbox. I would like to have a code that detects the tab and puts four spaces instead of 8. This is the code I used:
private sub text1_KeyDown(KeyCode as integer, Shift as Integer)
if keycode = vbKeyTab then
Text1.seltext = " "
KeyCode = 0
End if
Unfortunately, when the user pressed tab, it inserted my four spaces but then also inserted a tab (in the text box). I thought that the "keycode = 0" would cancel the tab so that only four spaces would appear, but I was wrong. Is there a way to do this?
-
Sep 7th, 2000, 09:52 AM
#6
Frenzied Member
I think you could use...
...the Text1_KeyPress Event
Code:
If KeyAscii = vbKeyTab Then
KeyAscii = 0
'MsgBox "TAB"
'Code for 4 spaces
End If
Did that help for ya?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 7th, 2000, 10:25 AM
#7
Thread Starter
Member
Doesn't seem to work for me.
I tried this just to test:
Private Sub form_KeyAscii(KeyAscii As Integer, Shift As Integer)
If KeyAscii = vbKeyS Then
KeyAscii = 0
Text1.SelText = "a"
End If
End Sub
And the output is "as" every time I hit the s key. How come it's not cancelling the "s"?
-
Sep 7th, 2000, 10:32 AM
#8
Thread Starter
Member
Correction...
I meant:
Private Sub Form_KeyDown(...
...
-
Sep 7th, 2000, 10:33 AM
#9
Frenzied Member
What?
Private Sub form_KeyAscii(KeyAscii As Integer, Shift As Integer)
Did you copy & paste it? or did you just typed it?
Maybe that's the prob hehe
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 7th, 2000, 10:38 AM
#10
Thread Starter
Member
Oops...
The error was in the retype, not the original. They need an embarrassed face in the icon selection.
In my application I typed "text1_KeyDown"
-
Sep 7th, 2000, 10:39 AM
#11
Frenzied Member
ok, KeyAscii means you have to enter the ASCII number for the number, so: S = 115
So use:
Code:
If KeyAscii = 115 Then
KeyAscii = 0
Text1.SelText = "a"
End If
That'll work
Please let me know if it works
[Edited by Jop on 09-07-2000 at 11:43 AM]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 7th, 2000, 10:44 AM
#12
Thread Starter
Member
Still a bug...
It turns out the Ascii value for s is 83 so I tried that instead as you suggested. I still get "as" returned. I really appreciate the time you are taking to try to help me out. This is incredibly frustrating.
-
Sep 7th, 2000, 10:57 AM
#13
Frenzied Member
hmm the UCase(s) = 83 yes 
but what isn't working then?
Please give me the code you're using... Wait I'll test it for ya one more time...
ok when I do:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 83 Then
KeyAscii = 0
Text1.SelText = "a"
End If
End Sub
It just adds a to the text that's already in the box!
Damn I don't get it
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 7th, 2000, 10:58 AM
#14
Frenzied Member
hmm the UCase(s) = 83 yes 
but what isn't working then?
Please give me the code you're using... Wait I'll test it for ya one more time...
ok when I do:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 83 Then
KeyAscii = 0
Text1.SelText = "a"
End If
End Sub
It works for me when I press <Shift> + s
It just adds a to the text that's already in the box!
Damn I don't get it why it won't work for you... please test it with this code.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 7th, 2000, 11:06 AM
#15
Thread Starter
Member
Halleluia!!!
It's the difference between KeyDown and KeyPress apparently. When I copied and pasted your code it worked for me also. Thank you, Thank you, Thank you. Your name will go into the credits.
-
Sep 7th, 2000, 11:18 AM
#16
Frenzied Member
Thank you, Thank you, Thank you. Your name will go into the credits
I would love it (you to put my name in the credits) but it's not neccesary, but again, no problem if you do 
also, you can add me via ICQ (18818940) if ya want!
BTW, what does the prog?
[Edited by Jop on 09-07-2000 at 12:24 PM]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
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
|