Results 1 to 13 of 13

Thread: MsgBox and flags - please about explanation

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    MsgBox and flags - please about explanation

    Hi All

    My prob it's like this.

    I get to know, that I should to write for procedure this message box instead of sign '+' it a logic expression - 'Or'.

    e.g. instead

    VB Code:
    1. MsgBox "Item " & Text1.Text & " was not found!", vbOKOnly + vbInformation, "Search"

    should be:
    VB Code:
    1. MsgBox "Item " & Text1.Text & " was not found!", vbOKOnly [B]Or[/B] vbInformation, "Search"

    I was explained that this depends from quantity of flags

    I am totally confused now because I don't know what are the flags. How I can to recognize them? Where I can read about flags for Message Box - on a MSDN I can't found it

    thanks in advance
    I know, I know, my English is bad, sorry .....

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: MsgBox and flags - please about explanation

    These flags are binary values - so they should be added together with the OR operator. + does the same thing but is considered inappropriate.

    Here's an explanation - and to understand it you must consider what these values look like in binary.

    0001 is the decimal value 1
    0010 is the decimal value 2

    1 + 2 = 3 (this is standard math)
    1 OR 2 = 3 (this is done with boolean logic)

    0001 (1)
    0010 (2) - now let's OR these values
    ----
    0011 (3) - the result of OR'ing the two values together

    OR follows the rule that if either bit is true the results is true...

    1 + 3 = 4 (this is standard math)
    1 or 3 = 3 (see below for why)

    0001 (1)
    0011 (3)
    ----
    0011 (3) - the result of OR'ing the decimal values 1 and 3 together

    See how the "1" bit in an OR can still only produce a "1" in the binary 1 column?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: MsgBox and flags - please about explanation

    You can see all the flags that you can use right clicking one of them and selecting Definition. What each Flag does? it's pretty self explained in the Flag's name, the only thing you need to do is adding the flags you want using + or OR
    Example, you say..
    Oh I want a message box asking something, the answer should be yes or no, i also want a question image, default button should be NO, the Messagebox name should be MyMessageBox.
    Then you need this
    VB Code:
    1. If MsgBox("Yes or No?", vbYesNo + vbQuestion + vbDefaultButton2, "MyMessageBox") = vbYes Then
    2.         'Yes
    3.     Else
    4.         'No
    5.     End If
    Last edited by jcis; Jan 14th, 2007 at 12:02 PM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: MsgBox and flags - please about explanation

    Thanks, very thanks Szlamany. It a good deal to explain.

    But still I don't know how I can to recognize them?
    I want ask you.

    Are relationships between the flags and values assigns to a message box.
    You have mean about these five groups of values? You know.

    first group determines which buttons to display
    second group determines which icon to display
    trd group determines which button is the default
    forth group determines the modality of the message box
    fifth group it the constants that can be used for the buttons argument which would only be used under special circumstances

    Yet is a sixth group of value which determines which button the user clicked

    And this can it's something of different completely

    thanks Tamgovb
    I know, I know, my English is bad, sorry .....

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: MsgBox and flags - please about explanation

    You are referring to this:

    Code:
    vbOKOnly		0 Display OK button only. 
    vbOKCancel		1 Display OK and Cancel buttons. 
    vbAbortRetryIgnore	2 Display Abort, Retry, and Ignore buttons. 
    vbYesNoCancel		3 Display Yes, No, and Cancel buttons. 
    vbYesNo			4 Display Yes and No buttons. 
    vbRetryCancel		5 Display Retry and Cancel buttons. 
    vbCritical 		16 Display Critical Message icon. 
    vbQuestion 		32 Display Warning Query icon. 
    vbExclamation 		48 Display Warning Message icon. 
    vbInformation 		64 Display Information Message icon. 
    vbDefaultButton1 	0 First button is the default. 
    vbDefaultButton2 	256 Second button is the default. 
    vbDefaultButton3 	512 Third button is the default. 
    vbDefaultButton4 	768 Fourth button is the default. 
    vbApplicationModal 	0 Application modal. The user must respond to the message box 
    			before continuing work in the current application. 
    vbSystemModal 		4096 System modal.
    vbMsgBoxHelpButton 	16384 Adds Help button to the message box 
    VbMsgBoxSetForeground 	65536 Specifies the message box window as the foreground window 
    vbMsgBoxRight 		524288 Text is right aligned 
    vbMsgBoxRtlReading 	1048576 Specifies text should appear as right-to-left reading...
    
    The first group of values (0–5) describes the number and type of buttons displayed 
    in the dialog box; 
    the second group (16, 32, 48, 64) describes the icon style; 
    the third group (0, 256, 512) determines which button is the default; 
    and the fourth group (0, 4096) determines the modality of the message box. 
    When adding numbers to create a final value for the buttons argument
    , use only one number from each group.
    I don't see a 5th group mentioned here... The constants shown in the help message that followed this indicate what key/button was clicked by the user...

    At any rate - these "groups" are simply parts of the "bit pattern" that controls behavior.

    So if you look at what they are calling the "first" group you will see that they are getting a lot of information passed to the function by simply using 3 bits.

    Code:
    Bit [0] Value 1 
    Bit [1] Value 2 
    Bit [2] Value 4 
    
    421
    ---
    000 - decimal 0 - vkOKOnly
    001 - decimal 1 - vbOKCancel
    010 - decimal 2 - vbAbortRetryIgnore
    011 - decimal 3 - vbYesNoCancel
    100 - decimal 4 - vbYesNo
    101 - decimal 5 - vbRetryCancel
    
    110 - decimal 6 - not used
    111 - decimal 7 - not used
    The code in the MSGBOX function can simply check these bits and knows exactly what button combinations to show. Checking a bit is done like this:

    Code:
    If (lngBitPattern and 1) <> 0 Then
         ' bit 0 (value 1) is set - let's do something
    Else
         ' bit 0 (value 1) is not set - let's do something else...
    End If
    VB is trying to be easy-to-use by suggesting that you can "add" these values together - but of course adding bits with + operator can cause "carry over" values into other columns - OR is always preferred. To let novice programmers get around having to grasp this fact the help text goes on to say that only one value should be "added" from each group.

    Are you asking for explanations of this specific to MSGBOX or are you trying to understand the whole bit pattern concept??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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

    Re: MsgBox and flags - please about explanation

    Not sure if you guys noticed but the Or does work for adding the values but you dont get the intellisense with it to produce the menu of the next possible flag to add. When you use the "+" sign you do get the intellisense. I have been using the "+" because of this for many years as its easier to pick from a list then type it all out (yes, I do know almost all the arguments by heart lol).

    Also, there is only 4 groups of flag possibilities you can add or Or together.

    Button captions
    Icon type
    Default button
    Modality level

    VB Code:
    1. MsgBox "Message", vbYesNo + vbInformation + vbDefaultButton2 + vbSystemModal, "Title"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: MsgBox and flags - please about explanation

    Quote Originally Posted by RobDog888
    Not sure if you guys noticed but the Or does work for adding the values but you dont get the intellisense with it to produce the menu of the next possible flag to add. When you use the "+" sign you do get the intellisense. I have been using the "+" because of this for many years as its easier to pick from a list then type it all out (yes, I do know almost all the arguments by heart lol)
    Intellisense works fine for me:

    Attached Images Attached Images  

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

    Re: MsgBox and flags - please about explanation

    Hmm, must be something to do with editing the "+" and switching it for an OR that it wont work. If I edit an Or for a + then it will popup. .[/color]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: MsgBox and flags - please about explanation

    I cant believe I missed that you can change the RTL Reading too After all these years I never noticed them. Too bad you cant easily change the order of the text in the buttons too. 's Steve.
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: MsgBox and flags - please about explanation

    You could take the easy way out and get MZTools
    It has a great tool for making MsgBoxes.

    Or try the one in my sig

  11. #11
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: MsgBox and flags - please about explanation

    The on and off bits for flags are often exclusive or usually the same bits are not turned in different flags within a group... so 1+3=4 (standard math) and 1 or 3=3 wouldn't normally be an issue with flags casue you wouldn't have a flag=3 if there's a flag=1... that's why you have to +/Or them in order to get the on-bits combination you require.

  12. #12
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: MsgBox and flags - please about explanation

    Quote Originally Posted by leinad31
    The on and off bits for flags are often exclusive or usually the same bits are not turned in different flags within a group...
    But that is not the case with the MSGBOX flags. They are using the absense of all flags and certain combinations of flags to mean specific conditions (as I posted in post #5).

    If you look closely at the "combinations" of flags they actually make a lot of sense. You can almost understand how the function grew with functionality over the versions and releases of VB.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: MsgBox and flags - please about explanation

    You mean this?
    vbOKOnly 0 Display OK button only.
    vbOKCancel 1 Display OK and Cancel buttons.
    vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.
    vbYesNoCancel 3 Display Yes, No, and Cancel buttons.
    vbYesNo 4 Display Yes and No buttons.
    vbRetryCancel 5 Display Retry and Cancel buttons.
    yup its an exception to the typical, which is understandable considering you have only 4-bits alloted for the button combinations.

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