0

I got confused when I want to add double quotes and use concatenation in the meantime.

I understand if I want to show double quotes, I can use """a""", which will print "a" cause "a" is a string and two pairs double quotes will let the machine knows we want to show one pair.

But I don't understand the situation below:

Sub test()
    Dim aVar As String
    Dim bVar As String
    Dim Parameters As String: Parameters = "a"
    aVar = "param builtin=""" & "gaussian"""
    bVar = """" & Parameters & """"
    Debug.Print aVar 'print, param builtin="gaussian"
    Debug.Print bVar 'print, "a"
End Sub

In the case above, for aVar, I get confused when " and & come together. I don't why we don't use "param builtin=" & """gaussian""", which is making more sense to me. What's the difference between them and why this also works?

For bVar, why we have 4 pairs double quotes but just print "a". In my understanding, we should print ""a"".

Can anyone help me to explain this two situations here? Thank you!

Tony
  • 5
  • 3
  • 1
    What confuses me is why you don't just use `aVar = "param builtin=""gaussian"""`, and drop the concatenation entirely. I *presume* that an earlier version of the code looked more like `aVar = "param builtin=""" & SomeVariable & "gaussian"""` instead..? You may also want to read [this](https://stackoverflow.com/questions/10646142/what-does-it-mean-to-escape-a-string) question about Escaping Strings (it's for PHP, but the same *reasons* apply, even if the *application* is slightly different) – Chronocidal Jan 29 '20 at 17:12
  • For `bVar` - see what `Debug.Print """" & """"` returns. Or just `Debug.Print """"`. – BigBen Jan 29 '20 at 17:13
  • Thanks BigBen, I got what you said. – Tony Jan 29 '20 at 17:27
  • Cause I read other's people's code. I understand right now, thanks you! – Tony Jan 29 '20 at 17:28
  • You can also use `Chr(34)` and `string(2,34)` which still needs to be in line, but doesnt confuse matters with the `""`s `? chr(34) = " ? string(2,34) = ""` – Nathan_Sav Jan 29 '20 at 17:34

0 Answers0