|
-
Apr 16th, 2001, 01:30 AM
#1
Thread Starter
Lively Member
umm i have a slight problem. i don't want a user pressing the space bar in a text box, so i put in this:
Code:
If KeyAscii = 32 Then ' 32 is the KeyAscii for space bar
MsgBox ("Don't Press The Space Bar", vbExclamation, "NO SPACES")
so you can see i want it's Title to be "NO SPACES", the actual message to be "Don't Press The Space Bar" and it to be an exclamation style box...any help would be appreciated
I am stupid..but I AM 15 !
*a line from a song i wrote*
""""""""""""""""""""""""""""""""""""""""
so i came to say life bites away
whats done is done the past is gone
i cant believe the sh*t I know
i always wish it would just go
""""""""""""""""""""""""""""""""""""""""
"remember you Ps And Qs Boy !"
-
Apr 16th, 2001, 01:46 AM
#2
Hyperactive Member
try:
Code:
If KeyAscii = 32 Then ' 32 is the KeyAscii for space bar
MsgBox "Don't Press The Space Bar", vbExclamation, "NO SPACES"
End If
-
Apr 16th, 2001, 02:01 AM
#3
If you want to use your syntax then try setting a
var = to the message box -
If KeyAscii = 32 Then ' 32 is the KeyAscii for space bar
response = MsgBox ("Don't Press The Space Bar", vbExclamation, "NO SPACES")
-
Apr 16th, 2001, 02:19 AM
#4
Fanatic Member
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then ' 32 is the KeyAscii For space bar
KeyAscii = 0
MsgBox "Don't Press The Space Bar", vbExclamation, "NO SPACES"
End If
End Sub
-
Apr 16th, 2001, 02:26 AM
#5
Well ...
MsgBox is actually a function which returns a value corresponding to the user's response to the message. For e.g. if you provided two buttons, Yes and No, you can check the return value of the MsgBox statement to see if the user clicked on Yes or on No.
If you do not wish to use this return value, for e.g. you are only displaying a message for the user's information, it has only a single button OK and so the user response is immaterial, you can use the MsgBox statement without the parentheses. If you use parentheses, as in your original code, VB expects you to handle the return value of the function. If you omit the parentheses, VB knows that you don't want to handle the return value.
So, the following codes will produce an identical result:
Code:
Msgbox "This is just a warning",vbExclamation + vbOKOnly, "Just a warning"
Code:
Dim MyVar As Integer
MyVar = Msgbox("This is just a warning",vbExclamation + vbOKOnly, "Just a warning")
Code:
Call Msgbox("This is just a warning",vbExclamation + vbOKOnly, "Just a warning")
.
-
Apr 16th, 2001, 02:34 AM
#6
JamesM
may i ask why u changed Ascii to 0 in ur example. waste of a line of code
-
Apr 16th, 2001, 02:53 AM
#7
Well ...
If the KeyAscii = 0 is omitted, after displaying the message box, the space bar might still be entered in the textbox. KeyAscii corresponds to the character the user has pressed when the KeyPress event is fired. You can manipulate this variable, so that when the event closes, the actual value received by the textbox is something which you desire. If you set this variable to 0, the textbox receives nothing. If you do not set it to zero, the textbox might receive 32, which you do not want.
.
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
|