Or in MsgBox Function

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

    #1

    Or in MsgBox Function

    Can someone explain to me what the Or does here?

    Dim intReply as Integer = _
    MsgBox(strPromp t, MsgBoxStyle.OKC ancel Or
    MsgBoxStyle.Cri tical Or MsgBoxStyle.Def aultButton2,
    strTitle)

    I don't have VB on this cpu... will it display the ok and cancel
    buttons and the critical icon ... i still don't understand
    DefaultButton, can someone explain that to me as well? Thanks!

  • Adam Ruth

    #2
    Re: Or in MsgBox Function

    James wrote:
    Can someone explain to me what the Or does here?
    >
    Dim intReply as Integer = _
    MsgBox(strPromp t, MsgBoxStyle.OKC ancel Or
    MsgBoxStyle.Cri tical Or MsgBoxStyle.Def aultButton2,
    strTitle)
    >
    I don't have VB on this cpu... will it display the ok and cancel
    buttons and the critical icon ... i still don't understand
    DefaultButton, can someone explain that to me as well? Thanks!
    >
    In this context, Or is the bitwise operator. It allows you to combine
    bitfield values. In the way it's being used, it's exactly the same as
    using + For example

    If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then

    OKCancel Or Critical Or DefaultButton2 = 7
    OKCancel + Critical + DefaultButton2 = 7

    However Or is the better way to do it, since it keeps you from adding
    the same value twice:

    OKCancel + Critical + DefaultButton2 + OKCancel = 8
    OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7

    Do an Internet search for "Bitwise Operators" and you'll probably find
    some better explanations.

    DefaultButton determines which button on the Message Box has focus when
    it is shown. If you pick DefaultButton2 and OKCancel then Cancel would
    be in focus an would be the action if the user pressed the space bar or
    the Enter key. DefaultButton1 would be the OK button (left to right).

    Adam Ruth

    Comment

    • James

      #3
      Re: Or in MsgBox Function

      so since sgBoxStyle.OKCa ncel = 1
      MsgBoxStyle.Cri tical = 16
      MsgBoxStyle.Def aultButton2 = 256

      does that make the bitwise value 273? which is then the value of
      intReply? Sorry, I've never delt with this "bitwise" stuff... What is
      this used for? Thanks!


      Adam Ruth wrote:
      James wrote:
      Can someone explain to me what the Or does here?

      Dim intReply as Integer = _
      MsgBox(strPromp t, MsgBoxStyle.OKC ancel Or
      MsgBoxStyle.Cri tical Or MsgBoxStyle.Def aultButton2,
      strTitle)

      I don't have VB on this cpu... will it display the ok and cancel
      buttons and the critical icon ... i still don't understand
      DefaultButton, can someone explain that to me as well? Thanks!
      >
      In this context, Or is the bitwise operator. It allows you to combine
      bitfield values. In the way it's being used, it's exactly the same as
      using + For example
      >
      If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then
      >
      OKCancel Or Critical Or DefaultButton2 = 7
      OKCancel + Critical + DefaultButton2 = 7
      >
      However Or is the better way to do it, since it keeps you from adding
      the same value twice:
      >
      OKCancel + Critical + DefaultButton2 + OKCancel = 8
      OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7
      >
      Do an Internet search for "Bitwise Operators" and you'll probably find
      some better explanations.
      >
      DefaultButton determines which button on the Message Box has focus when
      it is shown. If you pick DefaultButton2 and OKCancel then Cancel would
      be in focus an would be the action if the user pressed the space bar or
      the Enter key. DefaultButton1 would be the OK button (left to right).
      >
      Adam Ruth

      Comment

      • Adam Ruth

        #4
        Re: Or in MsgBox Function

        James wrote:
        so since sgBoxStyle.OKCa ncel = 1
        MsgBoxStyle.Cri tical = 16
        MsgBoxStyle.Def aultButton2 = 256
        >
        does that make the bitwise value 273? which is then the value of
        intReply?
        Correct, the total of those values is 273. intReply in your example
        would actually be set to a value of type MsgBoxResult which would
        indicate which button the user pressed. 273 is a number that is passed
        to the function which tells the function how to display the message box.
        Sorry, I've never delt with this "bitwise" stuff... What is
        this used for? Thanks!
        No problem, it can be a bit confusing when first encountered. Bitfields
        are a way to combine several options into one parameter. Instead of
        having separate parameters for each of the options, you combine the set
        of options into one number with the Or operator. You'll notice that the
        values for each of the options are each double the other one, you have
        1, 2, 4, 8, 16, 32, 64, 256, etc. This is because each number
        represents a bit in a 32-bit number.

        Wikipedia has a good description of how bitwise operations work. Think
        of the options parameter as a set of 32 on/off switches and each of the
        options (that are joined with Or) as turning on one of the 32 options.



        Adam Ruth

        Comment

        • Dennis

          #5
          Re: Or in MsgBox Function

          You might check out the Flags attribute for Enumerations. The Flag attribute
          makes the or'ing of different enumerations possible such that the receiving
          code, i.e.,, msgbox code, can easily decipher what different values of the
          Enumeration are passed.

          --
          Dennis in Houston


          "James" wrote:
          so since sgBoxStyle.OKCa ncel = 1
          MsgBoxStyle.Cri tical = 16
          MsgBoxStyle.Def aultButton2 = 256
          >
          does that make the bitwise value 273? which is then the value of
          intReply? Sorry, I've never delt with this "bitwise" stuff... What is
          this used for? Thanks!
          >
          >
          Adam Ruth wrote:
          James wrote:
          Can someone explain to me what the Or does here?
          >
          Dim intReply as Integer = _
          MsgBox(strPromp t, MsgBoxStyle.OKC ancel Or
          MsgBoxStyle.Cri tical Or MsgBoxStyle.Def aultButton2,
          strTitle)
          >
          I don't have VB on this cpu... will it display the ok and cancel
          buttons and the critical icon ... i still don't understand
          DefaultButton, can someone explain that to me as well? Thanks!
          >
          In this context, Or is the bitwise operator. It allows you to combine
          bitfield values. In the way it's being used, it's exactly the same as
          using + For example

          If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then

          OKCancel Or Critical Or DefaultButton2 = 7
          OKCancel + Critical + DefaultButton2 = 7

          However Or is the better way to do it, since it keeps you from adding
          the same value twice:

          OKCancel + Critical + DefaultButton2 + OKCancel = 8
          OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7

          Do an Internet search for "Bitwise Operators" and you'll probably find
          some better explanations.

          DefaultButton determines which button on the Message Box has focus when
          it is shown. If you pick DefaultButton2 and OKCancel then Cancel would
          be in focus an would be the action if the user pressed the space bar or
          the Enter key. DefaultButton1 would be the OK button (left to right).

          Adam Ruth
          >
          >

          Comment

          • Steve Long

            #6
            Re: Or in MsgBox Function

            Hi Dennis,
            Just last week I looked this stuff up "again" and it appears that the Flags
            attribute doesn't really affect the way the bitmask works, just how the
            ..ToString() function treats the value.

            Correct me if I'm wrong...
            Steve

            "Dennis" <Dennis@discuss ions.microsoft. comwrote in message
            news:E8AD6D15-9CAF-4F08-A37F-DA4CD449DBD3@mi crosoft.com...
            You might check out the Flags attribute for Enumerations. The Flag
            attribute
            makes the or'ing of different enumerations possible such that the
            receiving
            code, i.e.,, msgbox code, can easily decipher what different values of the
            Enumeration are passed.
            >
            --
            Dennis in Houston
            >
            >
            "James" wrote:
            >
            >so since sgBoxStyle.OKCa ncel = 1
            >MsgBoxStyle.Cr itical = 16
            > MsgBoxStyle.Def aultButton2 = 256
            >>
            >does that make the bitwise value 273? which is then the value of
            >intReply? Sorry, I've never delt with this "bitwise" stuff... What is
            >this used for? Thanks!
            >>
            >>
            >Adam Ruth wrote:
            James wrote:
            Can someone explain to me what the Or does here?
            >
            Dim intReply as Integer = _
            MsgBox(strPromp t, MsgBoxStyle.OKC ancel Or
            MsgBoxStyle.Cri tical Or MsgBoxStyle.Def aultButton2,
            strTitle)
            >
            I don't have VB on this cpu... will it display the ok and cancel
            buttons and the critical icon ... i still don't understand
            DefaultButton, can someone explain that to me as well? Thanks!
            >
            >
            In this context, Or is the bitwise operator. It allows you to combine
            bitfield values. In the way it's being used, it's exactly the same as
            using + For example
            >
            If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then
            >
            OKCancel Or Critical Or DefaultButton2 = 7
            OKCancel + Critical + DefaultButton2 = 7
            >
            However Or is the better way to do it, since it keeps you from adding
            the same value twice:
            >
            OKCancel + Critical + DefaultButton2 + OKCancel = 8
            OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7
            >
            Do an Internet search for "Bitwise Operators" and you'll probably find
            some better explanations.
            >
            DefaultButton determines which button on the Message Box has focus when
            it is shown. If you pick DefaultButton2 and OKCancel then Cancel would
            be in focus an would be the action if the user pressed the space bar or
            the Enter key. DefaultButton1 would be the OK button (left to right).
            >
            Adam Ruth
            >>
            >>

            Comment

            • Dennis

              #7
              Re: Or in MsgBox Function

              All I know is what I read in the MSDN under Flags attributes.
              --
              Dennis in Houston


              "Steve Long" wrote:
              Hi Dennis,
              Just last week I looked this stuff up "again" and it appears that the Flags
              attribute doesn't really affect the way the bitmask works, just how the
              ..ToString() function treats the value.
              >
              Correct me if I'm wrong...
              Steve
              >
              "Dennis" <Dennis@discuss ions.microsoft. comwrote in message
              news:E8AD6D15-9CAF-4F08-A37F-DA4CD449DBD3@mi crosoft.com...
              You might check out the Flags attribute for Enumerations. The Flag
              attribute
              makes the or'ing of different enumerations possible such that the
              receiving
              code, i.e.,, msgbox code, can easily decipher what different values of the
              Enumeration are passed.

              --
              Dennis in Houston


              "James" wrote:
              so since sgBoxStyle.OKCa ncel = 1
              MsgBoxStyle.Cri tical = 16
              MsgBoxStyle.Def aultButton2 = 256
              >
              does that make the bitwise value 273? which is then the value of
              intReply? Sorry, I've never delt with this "bitwise" stuff... What is
              this used for? Thanks!
              >
              >
              Adam Ruth wrote:
              James wrote:
              Can someone explain to me what the Or does here?
              >
              Dim intReply as Integer = _
              MsgBox(strPromp t, MsgBoxStyle.OKC ancel Or
              MsgBoxStyle.Cri tical Or MsgBoxStyle.Def aultButton2,
              strTitle)
              >
              I don't have VB on this cpu... will it display the ok and cancel
              buttons and the critical icon ... i still don't understand
              DefaultButton, can someone explain that to me as well? Thanks!
              >

              In this context, Or is the bitwise operator. It allows you to combine
              bitfield values. In the way it's being used, it's exactly the same as
              using + For example

              If OKCancel = 1 and Critical = 2 and DefaultButton2 = 4 then

              OKCancel Or Critical Or DefaultButton2 = 7
              OKCancel + Critical + DefaultButton2 = 7

              However Or is the better way to do it, since it keeps you from adding
              the same value twice:

              OKCancel + Critical + DefaultButton2 + OKCancel = 8
              OKCancel Or Critical Or DefaultButton2 Or OKCancel = 7

              Do an Internet search for "Bitwise Operators" and you'll probably find
              some better explanations.

              DefaultButton determines which button on the Message Box has focus when
              it is shown. If you pick DefaultButton2 and OKCancel then Cancel would
              be in focus an would be the action if the user pressed the space bar or
              the Enter key. DefaultButton1 would be the OK button (left to right).

              Adam Ruth
              >
              >
              >
              >
              >

              Comment

              Working...