[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
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 &
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
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.
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
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!