Results 1 to 16 of 16

Thread: sub procedure message box help

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4

    sub procedure message box help

    Can someone help me in getting started with this I need to setup a sub procedure that when called will display a message box. the string variable needs to be a passed value between the calling procedure and the called procedure. I need several different messages box to be displayed some with just ok buttons and some with yes.no buttons. Any information I would greatly appreciate because i'm stuck on this.

    thanks,
    Michael Giberson

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    A good start:
    Code:
    Public Sub DisplayMessageBox(ByVal strDisplay as String) 
    
    MessageBox.Show(strDisplay)
    
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4
    Thanks, how would i change what will be displayed in strmessage for each message box that i'm going to display, and what code would i write in to be able to change what buttons and icons will be displayed?

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I am not sure you are going down the right track with my code. Lets try again.

    To show a messagebox, all you have to do is:
    Code:
    MessageBox.Show("My message here", "Title Here")
    That will set the message and the title of the message box. You can do that anywhere you want in your code.

    Now, you can add more to it by adding the button types you want and the icon you want displayed by adding more:
    Code:
    MessageBox.Show("My Message here.", "Title Here", _
               MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    Changing the MessageBoxButtons.OK to other values will get you different buttons. The MessageBoxIcon.Exclamation is what is controling the icons. Changing those two values will allow you to customize the message box.

    Microsoft help on the subject:
    http://msdn.microsoft.com/library/de...classtopic.asp

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4
    I appreciate your help very much but i'm not sure i'm communicating the right thing across so i put in an example of what i need it to do

    start of example:
    Private Sub mnuCalcItem_Click

    DisplayMessagebox()
    and I need the message box to display the text, title, ok button, and error icon.

    Private Sub mnuSummary_Click

    DisplayMessagebox()
    I need the message box to display different text and title, and yes no buttons, and question icon.

    Private Sub Displaymessagebox()
    Messagebox.show()

    end example

    I'm not sure what to put into the messagebox.show inside of the Private Sub Displaymessagebox() so i can change what it says, what buttons are displayed, and icons displayed depending on which private sub called Displaymessagebox() and where do i state what exactly should be displayed, buttons show, and icons shown for each of the private subs?

    Thank you for your help so far,
    Michael Giberson

    p.s. if you would like you can email me at [email protected]

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I think what hellswraith is saying, and I agree with him, is that there is no point in having the MessageBox in another sub. The MessageBox method itself is only one line or one method so why move it to another sub? It just makes things harder than they need to be.
    VB Code:
    1. 'start of example:
    2. Private Sub mnuCalcItem_Click
    3.  
    4. MessageBox.Show("My Text Message Here", "Caption or Title Here", MessageBoxButtons.OK, MessageBoxIcon.Error)
    5. 'and I need the message box to display the text, title, ok button, and error icon.
    6.  
    7. Private Sub mnuSummary_Click
    8.  
    9. MessageBox.Show("My Text Message Here", "Caption or Title Here", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    10. 'I need the message box to display different text and title, and yes no buttons, and question icon.
    11.  
    12. 'end example

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4
    Thanks to both of you guys for the help but unfortunately my project specifications say that i need to do this, and that's why I had to try and find some help on it because I couldn't figure it out.

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Those specifications are not very good then.

    Anyway, you will basically create your Displaymessagebox() to accept all the arguments a messagebox accepts, then you pass those arguments down to the actual call to show the messagebox.

    This is soooooooooo much bad design. It isn't accomplishing anything, and adds complication for NO reason. You need to talk to your boss, teacher, or whatever and ask why.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    I think I can guess why.... the person who created the spcs subscribes to the "One sub, one action" theory..... and takes it to the ultimate degree..... bad juju...

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by techgnome
    I think I can guess why.... the person who created the spcs subscribes to the "One sub, one action" theory..... and takes it to the ultimate degree..... bad juju...

    TG
    I can understand that, but all this person will be doing is creating a wrapper around a sub that already has one action.

    The messagebox is a class, and Show is the method in that class. It is already overloaded and done. There is no reason to wrap it up in another sub....just doesn't makes sense.

    Like you said, bad juju....

  11. #11
    New Member
    Join Date
    Nov 2006
    Posts
    6

    Re: sub procedure message box help

    Well i have read through the above replies and indeed they helped alot too. So here is my query, iam displaying the messagebox on the ItemUpdating event of my gridview. The messagebox pops up with three buttons( yes,no,cancel) but clicking ok or cancel just gives me same results i.e when i click cancel, instead of canceling the updating operation, the gridview goes a head and updates even after clicking cancel.
    Qn. How do make sure that clicking cancel stops updating the record.

  12. #12
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: sub procedure message box help

    This sounds to me like a school assignment. When you call the messagebox that is more than just an ok button, you should assign it to an integer then test that integer to see which button they pressed:
    VB Code:
    1. Dim i As Integer
    2.         i = MsgBox("Click Yes to do something, No to Deny or Cancel to Exit")
    3.         Select Case i
    4.             Case vbYes
    5.                 'Do Something
    6.             Case vbNo
    7.                 'Do Something
    8.             Case vbCancel
    9.                 'Do Something
    10.         End Select
    As for stopping the gridview from updating, it has a canceledit method that you can use and will discard all changes and cancel the update. I hope that helps some.

  13. #13
    New Member
    Join Date
    Nov 2006
    Posts
    6

    Re: sub procedure message box help

    [QUOTE=dminder]This sounds to me like a school assignment. When you call the messagebox that is more than just an ok button, you should assign it to an integer then test that integer to see which button they pressed:
    VB Code:
    1. Dim i As Integer
    2.         i = MsgBox("Click Yes to do something, No to Deny or Cancel to Exit")
    3.         Select Case i
    4.             Case vbYes
    5.                 'Do Something
    6.             Case vbNo
    7.                 'Do Something
    8.             Case vbCancel
    9.                 'Do Something
    10.         End Select
    As for stopping the gridview from updating, it has a canceledit method that you can use and will discard all changes and cancel the update. I hope that helps some.[Yes this forum is a school and iam learning, real starter or is the forum closed for starters. ]

  14. #14
    New Member
    Join Date
    Nov 2006
    Posts
    6

    Re: sub procedure message box help

    Yes this forum is a school, isn't it and iam learning, real starter or is the forum closed for starters.

  15. #15
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: sub procedure message box help

    No, the forum is not closed for learning, however most of us who post here do not like to do homework assignments for people. We would rather give them the ability and direction to learn the technologies themselves. There have been a few who have tried to snowball people on here into giving them the entire answer instead of putting in the time and effort most of us have to actually learn.

    Anyways, I hope that bit of code I previously posted gets you to where you need. If you run into further problems or errors feel free to post them and we will be glad to be of assisstance.

    D

  16. #16
    New Member
    Join Date
    Nov 2006
    Posts
    6

    Re: sub procedure message box help

    Ok, hope to keep around then, otherwise i was about to step a side and give room for the Gurus .

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