0

Back in VB6, you were able to re-assign a string's value to itself plus other string values, such as:

str_Duplications_Line = str_Duplications_Line & pRow_Prime.Value(i_FieldNum)

Now, intellisense is not picking it up as an error, nor is the compiler complaining, but when it is ran, it bombs out on that line, and other multiple line such as these:

str_Duplications_Line = str_Duplications_Line & ","

str_Duplications_AllFields = str_Duplications_AllFields + str_Duplications_Line + vbCrLf

Any idea why this is happening, and how I can fix this? Or at least, simulate the same thing in VB.NET?

Logan B. Lehman
  • 4,637
  • 7
  • 31
  • 44
  • 4
    "Bombs out"? Is there an error? Errors usually contain useful information about what went wrong. Both the `+` and `&` operators can be used to concatenate strings. Somewhat related: http://stackoverflow.com/questions/3006153/vb-net-ampersand-vs-plus-for-concatenating-string – David May 19 '12 at 23:16
  • What do you mean by `bombs out` ? What error are you getting? – jams May 19 '12 at 23:27

2 Answers2

3

Here is the diference between & and +

"abc" + "def" = "abcdef"
"abc" & "def" = "abcdef"
"111" + "222" = "111222"
"111" & "222" = "111222"
"111" & 222 = "111222"
"111" + 222 = 333
"abc" + 222 = conversion error

If any one operand is null, you may get an error.

Krishanu Dey
  • 6,212
  • 6
  • 50
  • 67
2

Make sure you're not trying to concatenate a null to your string

web_bod
  • 5,688
  • 1
  • 16
  • 25