Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > MsgBox variables


Reply
 
Thread Tools Display Modes
  #1  
Old 10-08-2004, 02:12 PM
mrhyde mrhyde is offline
Centurion
 
Join Date: Aug 2004
Posts: 112
Default MsgBox variables


Is there a way to put a variable in the first part of this statement:

Answer = MsgBox("Would you like to Print Preview this range?", vbQuestion + vbYesNo, "Confirm Preview")

I would like to be able to have an output of:

Would you like to Print Preview this range(1)?


Any help would be appreciated. Thanks.
Reply With Quote
  #2  
Old 10-08-2004, 02:17 PM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

You can concatenate the value into the string.
Code:
' I use a string variable but it's not necessary. Dim strMessage As String ' Here I use varRangeValue as a place holder for what ever value you want to ' concatenate into the string. strMessage = "Would you like to Print Preview this " & varRangeValue & " Range?" ' Also note that I use a bitwise OR operation to combine the enumerator values for the ' Buttons argument of the MsgBox function. Answer = MsgBox(strMessage, vbQuestion Or vbYesNo, "Confirm Preview")
Edit:
Maybe I should clarify the note about the bitwise OR operation.

Let's say for argument sake that you made a boo-boo and entered in the values for the Buttons argument as:

vbQuestion + vbYesNo + vbYesNo

This would infact assign a value of 40 to the Buttons argument.

Whereas, if you use the bitwise OR operation and made the same boo-boo:

vbQuestion Or vbYesNo Or vbYesNo

This would assign the correct value of 36 to the Buttons argument.

This is because the Or statement used here is actually setting the bits that will make up the value passed and not adding all of the numbers together and then passing the resulting value.
__________________
The only stupid question is the one that goes un-asked.

Last edited by 00100b; 10-08-2004 at 02:29 PM.
Reply With Quote
  #3  
Old 10-08-2004, 02:25 PM
mrhyde mrhyde is offline
Centurion
 
Join Date: Aug 2004
Posts: 112
Default

Thanks. It works fine.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->