Results 1 to 6 of 6

Thread: [RESOLVED] How to use the results of an InputBox in the body of a MsgBox?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    12

    Resolved [RESOLVED] How to use the results of an InputBox in the body of a MsgBox?

    Hi there,

    I'm trying to figure out if there's a way to take what a user types into an input box and use that in the main message of a message box.

    For example:

    I could have an input box that says, "What's your favorite kind of ice cream?"

    The user types "Vanilla" and clicks OK.

    Then I have a message box that says, "Your favorite is Vanilla? Me too!"

    How do I enter the result of "Vanilla" in between two different pieces of text in a message box?

    Thanks

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: How to use the results of an InputBox in the body of a MsgBox?

    Code:
    Dim Answer As String
    
    Answer = InputBox ("What's your favorite kind of ice cream?")
    MsgBox "Your favorite is " & Answer & "? Me too!"
    To concatenate strings use &
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to use the results of an InputBox in the body of a MsgBox?

    One simple line that's all you need.
    .
    MsgBox "Your favorite is " & InputBox("What's your favorite kind of ice cream?") & " Me too!", vbOKOnly
    Last edited by jmsrickland; Nov 16th, 2012 at 01:18 AM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: How to use the results of an InputBox in the body of a MsgBox?

    Kerlen....are you taking a class? Do you have an reference books to help you learn VB6? While this forum is GREAT for honing skills, you might wanna take a class, or get yourself a good VB6 book and start from the beginning and work your way through it slowly. There are some basics you seem to be needing. I'd recommend a free on-line book called "The Black Book"--available at:
    http://portal.aauj.edu/portal_resour...black_book.pdf. Of course, there are MANY resources, including MSDN. But, a self-study book can't be beat. Good luck with VB.

  5. #5
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: How to use the results of an InputBox in the body of a MsgBox?

    its simple
    Code:
    Private Function MessageBox(Optional ByVal MsgBoxMessage As String, _
                                Optional ByVal InputBoxQuestion As String, _
                                Optional ByVal MsgBoxAnswer As String, _
                                Optional ByVal MessageBoxStyle As VbMsgBoxStyle, _
                                Optional ByVal MsgBoxTitle As String, _
                                Optional ByVal InputBoxTitle As String)
    MsgBox Left(IIf(MsgBoxMessage <> "", MsgBoxMessage, " "), Len(IIf(MsgBoxMessage <> "", MsgBoxMessage, " ")) - 1) & " " & _
     InputBox(InputBoxQuestion, InputBoxTitle) & _
      Right(IIf(MsgBoxMessage <> "", MsgBoxMessage, ""), 1) & " " & _
       MsgBoxAnswer, _
      MessageBoxStyle, _
     MsgBoxTitle
    End Function

    and to use this function (all are optional)
    Code:
    MessageBox [ByVal MsgBoxMessage As String], _
                       [ByVal InputBoxQuestion As String], _ 
                       [ByVal MsgBoxAnswer As String], _
                       [ByVal MessageBoxStyle As VbMsgBoxStyle], _
                       [ByVal MsgBoxTitle As String], _
                       [ByVal InputBoxTitle As String]
    Code:
    Private Sub Command1_Click()
    MessageBox "You favorite ice cream flavor is?", _
               "What is your favorite ice cream flavor?", _
               "Me too!", _
               vbOKOnly + vbInformation, _
               "Ice Cream Flavor", _
               "Ice Cream Flavor"
    End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    12

    Re: How to use the results of an InputBox in the body of a MsgBox?

    Thank you so much everyone! That definitely did the trick. I knew the answer had to be a simple one.

    And thank you Sam for the link to the book. I've been looking for a good course/study guide to start learning how to program better. I'll definitely take a look at it.

    All the best!

Tags for this Thread

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