Stupid Code :o)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric

    #1

    Stupid Code :o)

    What does "6" do... please explaine and why cantI use "5".

    Private Sub CmdVBOk_Click()
    intpress = MsgBox("Are you there", vbYesNo)
    If intpress = 6 Then
    MsgBox "Then pick up the darn phone"
    Else
    MsgBox "Ok Call ya later"
    End If
    End Sub

    Thank you
    Eric in Tampa


  • Randy Birch

    #2
    Re: Stupid Code :o)

    msgbox returns the value of the button pressed. vbOK= 1, vbCancel=2, ect.
    vbYes is 6. This example highlights the best practice of using named
    constants rather than literals in code.

    intpress = MsgBox("Are you there", vbYesNo)

    if intpress = vbYes then

    You can also use the return value directly, bypassing the extra variable:


    if MsgBox("Are you there", vbYesNo) = vbYes then

    Finally, a select case can also be used. This improves readability ...

    select case MsgBox("Are you there", vbYesNo)
    case vbYes
    case vbNo 'or case Else
    end select


    --

    Randy Birch
    MVP Visual Basic

    Please respond only to the newsgroups so all can benefit.


    "Eric" <eparker7@tampa bay.rr.com> wrote in message
    news:TqLfb.6706 $qw.632407@twis ter.tampabay.rr .com...
    : What does "6" do... please explaine and why cantI use "5".
    :
    : Private Sub CmdVBOk_Click()
    : intpress = MsgBox("Are you there", vbYesNo)
    : If intpress = 6 Then
    : MsgBox "Then pick up the darn phone"
    : Else
    : MsgBox "Ok Call ya later"
    : End If
    : End Sub
    :
    : Thank you
    : Eric in Tampa
    :
    :


    Comment

    Working...