none
What is wrong with my string assignment? RRS feed

  • Question

  • I am trying to assign a string to a variable by concatenating a combination of original text and other string variables; however, it is not working out the way I expect. My code is below

    strSQL = strPreviousComments1 & "; " & strrig1comments & "[#" & Date & "#] 

    strPreviousComments1 and strrig1comments are string variables and Date is the current Date.

    I want the string to end up looking like the following:

    MyPreviousComment; rig1comment [Date]

    .......where "Date" happens to be todays date.

    When I try to assign the variable the way it is written above, I don't get the results I expect.

    Thanks!

    Wednesday, June 26, 2013 3:46 PM

Answers

  • strSQL = strPreviousComments1 & "; " & strrig1comments & " [#" & Format(Date, "mm-dd-yyyy") & "#] "

    You need to format the date the way you want it. This example will result in the string

    "MyPreviousComment; rig1comment [#06-26-2013#] "

    Not sure if you really want the hash tags...

    • Marked as answer by ChemEng Wednesday, June 26, 2013 6:15 PM
    Wednesday, June 26, 2013 6:10 PM

All replies

  • By the way, the issue I am seeing is that I am getting an "expected end of statement" error at the semicolon.
    Wednesday, June 26, 2013 4:16 PM
  • strSQL = strPreviousComments1 & "; " & strrig1comments & " [#" & Format(Date, "mm-dd-yyyy") & "#] "

    You need to format the date the way you want it. This example will result in the string

    "MyPreviousComment; rig1comment [#06-26-2013#] "

    Not sure if you really want the hash tags...

    • Marked as answer by ChemEng Wednesday, June 26, 2013 6:15 PM
    Wednesday, June 26, 2013 6:10 PM