Concatenating Anomale RRS feed

  • Question

  • Why does the message box only return 01 instead of 01a?  What's a work around?

    Sub WTF()
    Dim txt1 As String
    Dim txt2 As String
    Dim txt3 As String
    Dim txt4 As String
    txt1 = 0
    txt2 = 1
    txt3 = a
    txt4 = txt1 & txt2 & txt3
    mb = MsgBox(txt4, vbOKOnly)
    End Sub

    Wednesday, September 18, 2013 6:08 PM

All replies

  • Literal string values should be enclosed in quotes:

        txt3 = "a"

    In the original line

        txt3 = a

    a is interpreted as an (undeclared) variable. Its value is empty since it hasn't been assigned a value.

    If you had required all variables to be declared explicitly, you'd have received an error message about a being unknown. See The importance of 'Option Explicit'.

    Regards, Hans Vogelaar (

    • Proposed as answer by Ron Rosenfeld Sunday, September 22, 2013 12:06 AM
    Wednesday, September 18, 2013 6:38 PM