Results 1 to 13 of 13

Thread: MessageBox and button options

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244

    MessageBox and button options

    I know this is going to sound like a very stupid question but I have never done this before.

    I have a MessageBox that prompts the user if they want to continue if certain files exist. That part of the code is working. What I have never done before and what I don't know how to do is perform an action based on what button they choose on the message box. I don't what where that result is stored or how to call it.

    Feel free to laugh at this question.

    Jim

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Talking

    Nothing better than a free laugh !!!


    If you type:
    VB Code:
    1. if msgbox("Continue ?",MsgBoxStyle.YesNo) =

    Intellisense shows you a list of options....

    VB Code:
    1. if msgbox("Yes",MsgBoxStyle.YesNo) =  MsgBoxResult.OK Then
    2.  'do this
    3. else
    4.  'do this
    5. End if

  3. #3
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Well not to be overly picky but:
    if msgbox("Yes",MsgBoxStyle.YesNo) = MsgBoxResult.OK Then

    This will never return MsgBoxResult.OK, since the box doesn't have an OK button. It'll return either MsgBoxResult.Yes or MsgBoxResult.No.

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Lol... Yes very true.... but a few runs of the debugger he or I would of caught that...

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Also, use MessageBox.Show() instead of msgbox

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244
    I aim to provide the entertainment value to this forum

  7. #7
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    What's the difference between using MessageBox.Show() and just msgbox()?

  8. #8
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    MsgBox is there just for backward compatibility. The .NET class that provides the same functionality is Messagebox.Show.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  9. #9
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Ah I understand - if so then you should also probably use the MessageBoxButtons enum instead of MsgBoxStyle huh. I don't see an equivalent for MsgBoxResult?

    edit: oh it's DialogResult.

  10. #10
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well that explains why I was getting a reference to the Microsoft.VB library....

  11. #11
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Is that necessarily bad practice? It seems to me that using stuff in the VisualBasic namespace will work the same, it just makes references to classes that are VB-specific (so your resulting IL won't translate into other languages).

  12. #12
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I don't think it is bad practice, but it will help if you use the framework classes instead of the VB namespaces if you can. The reason I say that is because the more familiar you are with the .net classes, the easier it is to actually convert code from other languages over to VB.Net.

    I also think that the compatibility classes that you are calling, are actually wrappers that call the .Net Framework classes. So why would you want to add another layer in there when you can bypass it all together? I haven't verified this, but it seems to me that was all they did.

  13. #13
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    You're probably right (as was Pirate earlier when he pointed out something similar to me, I just didn't get it then).

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