0

I have a basic VBA question. See my code below, I would expect an error message for the first msgbox because you can't calculate an integer plus a string, but that's not the case. What is happening? Why, VBA seems to be changing data type here? Thanks in advance.

Sub calc1()
  Dim x As String
  x = 100
  MsgBox 1 + x ' display 101
  Msgbox "1" + x ' display 1100
End Sub
2
  • 1
    + is two things, depending on context ("addition" operator, or "concatenation" operator). If you want to concatenate strings, use the & operator instead. Yes, VBA is doing implicit conversions behind your back. All. The. Time. But JavaScript is even worse. Commented Jan 18, 2017 at 18:20
  • Related: stackoverflow.com/questions/11595226/… Commented Jan 18, 2017 at 18:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.