|
-
Nov 15th, 2012, 07:04 PM
#1
Thread Starter
New Member
[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
-
Nov 15th, 2012, 07:43 PM
#2
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 ...
-
Nov 15th, 2012, 07:46 PM
#3
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.
-
Nov 15th, 2012, 07:53 PM
#4
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.
-
Nov 16th, 2012, 12:17 AM
#5
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
-
Nov 19th, 2012, 01:36 PM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|