Results 1 to 7 of 7

Thread: MsgBox isn't doing what i want it to

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Dullawhere
    Posts
    100

    Question

    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 !"

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    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

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Cool

    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")

  4. #4
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    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

  5. #5
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    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")
    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  6. #6
    TheSarlacc
    Guest

    JamesM

    may i ask why u changed Ascii to 0 in ur example. waste of a line of code

  7. #7
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    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.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width