Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using MsgBox

1 view
Skip to first unread message

mnewhart

unread,
Aug 24, 2001, 4:39:37 PM8/24/01
to
When I use the following, it works fine:
* MsgBox ("This is some text")
* MsgBox ("This is some text with attitude" + "!")

When I try the following, it doesn't work, telling me of some case mismatch?
I declare something like Dim someInteger As Integer
I set someInteger = 1
I try to do:
* MsgBox ("Variable someInteger's value is = " + someInteger)
This doesn't work. What do I need to do to make this work?

Jay Freedman

unread,
Aug 24, 2001, 5:03:44 PM8/24/01
to
Use the & operator instead of the + operator.

--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word

"mnewhart" <mnew...@eudoramail.com> wrote in message
news:#dlQKzNLBHA.1312@tkmsftngp07...

mnewhart

unread,
Aug 24, 2001, 5:25:58 PM8/24/01
to
Thank you that fixed that. But why do you have to do that? It doesn't make
sense to have
** MsgBox ("This is some text" + "This is more text")
when you can just do
** MsgBox ("This is some textThis is more text")

Is there a reason for the (+) sign if when you want to show multiple things
of different types, you have to use the (&) sign?

Thanks again for helping!


Jay Freedman <jay.fr...@verizon.net> wrote in message
news:uguVEBOLBHA.1496@tkmsftngp05...

mnewhart

unread,
Aug 24, 2001, 6:08:05 PM8/24/01
to
ok, I think I answered my own question. Ampersand is to concatenate and
plus is used for arithmetic. However, plus does actually work with strings,
but if any part of the expression can be interpreted as a number, VBA will
literally to add them together.

Jay Freedman

unread,
Aug 24, 2001, 9:22:17 PM8/24/01
to
Yes, you're getting close.

One of the rules of computer programming languages is that a binary operator
(technical term for +, -, &, and other symbols that combine two things) must
have the same data type on both sides. That's often inconvenient for the
human programmer. In some circumstances, where it makes sense, the language
is allowed to do "implicit" conversions (that is, they're allowed to happen
without an explicit function call) on one of the two objects to make it the
same data type as the other.

In the case of

"The value is " & myInteger

VBA is allowed to convert the integer to its string representation. It knows
the result has to be a string because the ampersand is a string operator.
When you tried to use a plus sign in the same kind of expression, VBA said
"you're telling me to convert the string on the left into a number, but
that's not an allowed conversion".

The use of the plus sign to concatenate two strings is a special case that
probably shouldn't be allowed. I think somebody at Microsoft just got tired
of people complaining, and put in the rule "if both sides are strings,
pretend it's an ampersand". :-)

--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word


"mnewhart" <mnew...@eudoramail.com> wrote in message

news:uWMamkOLBHA.1916@tkmsftngp07...

mnewhart

unread,
Aug 27, 2001, 1:23:32 PM8/27/01
to
oh ok, I understand now. Thanks so much for clearing that up for me Jay! :)

Melissa


Jay Freedman <jay.fr...@verizon.net> wrote in message

news:#FHlVSQLBHA.1372@tkmsftngp07...

0 new messages