Home > Mobile >  Trouble creating a comma-separated output string using variables
Trouble creating a comma-separated output string using variables

Time:04-13

I am trying to create a string output where each of the variables are quoted and separated by a comma. This is the code I'm trying to use.

objOutputFile7.WriteLine(""& strCodeSetName & "'","'" & strCreateID & "'","'" & strSiteCode & "'","'" & strSiteName & "'","'" & strSiteName &"'",""false",,,,"false"")

I've been bouncing between 2 different errors. One that tells me a cannot use parentheses while calling a Sub. The other stating it's expecting a close-parentheses inside one of the variable names.

I've looked through online resources and could not find a close example. Could someone help me resolve my conundrum?

CodePudding user response:

It's difficult to know exactly what output you expect/want, but maybe something like this?

objOutputFile7.WriteLine "'" & strCodeSetName & "','" & _
          strCreateID & "','" & strSiteCode & "','" & _
          strSiteName & "','" & strSiteName & "',false,,,,false"

CodePudding user response:

One possibility is using the Join function. You have to create an array with all your variables...

Dim outLine as String
Dim myValues as Variant
myValues = Array(strCodeSetName, strCreateID, strSiteCode, _
                 strSiteName, strSiteName, "false,,,,false")
outLine = Join(myValues, ",")
objOutputFile7.WriteLine outLine
  •  Tags:  
  • vba
  • Related