I have a problem when I try to convert my Array into a comma-separated String. In the example below, I retrieve all the files in my email and send them to my server to add them. My server sends me back an ID that is stored in the Array. Then I try to convert this Array into a String.
Dim filesId(1 To 100) As String
Dim tmpString As String
Dim count As Integer
count = 0
Set db = Session.Currentdatabase
Set CurrentDocColl = db.Unprocesseddocuments
Set doc = CurrentDocColl.Getfirstdocument
While Not doc Is Nothing
Set item = doc.GETFIRSTITEM("Body")
If doc.HasEmbedded Then
ForAll attachment In item.EmbeddedObjects
jsonBody="value={""filename"":"""+attachment.Name+"""}"
Set http=session.CreateHTTPRequest()
http.preferstrings = True
Call http.SetHeaderField("ContentType","application/json")
ret = http.Post(url, jsonBody)
If IsNumeric(ret) Then
count = count + 1
filesId(count) = ret
Else
MessageBox ret
End If
End ForAll
End If
Set doc=CurrentDocColl.Getnextdocument(doc)
Wend
ForAll itemValue In filesId
If CStr(itemValue ) <> "" Then
If tmpString = "" Then
tmpString = itemValue
Else
tmpString = tmpString & "," & itemValue
End If
End If
End ForAll
MessageBox tmpString
The problem is that the final String contains only the first value of the array and not the next values.
Example with this Array: [3567,3568,3569,3570]
Desired result String: 3567,3568,3569,3570
Result received: 3567
I don't understand where this problem comes from, especially since it also doesn't work with the Join() and Implode() functions.
EDIT
Indeed after having looked in the debugger, we can see that my data are present in the Array but in a particular format because the quotes of the strings do not close. What can I do to fix this?
Thank you very much for your help
Your http post result contains line break at its end. That is why the string looks so "strange" in debugger. This resuls in the following tmpString:
"3267
,3268
,3269
,3270"
Messagebox is not able to show all line breaks... so it only shows the string until the first line break.
You need to remove line breaks from your string before concatenating:
Dim badChars(2) as String
Dim goodChars(2) as String
badChars(0) = Chr$(0)
badChars(1) = Chr$(10)
badChars(2) = Chr$(13)
...
filesId(count) = Replace( ret, badChars, goodChars )
As I do not know WHICH line break / carriage return is there in your string I replace the three most common ones with blank in above code... Might be another unprintable character in there that you have to get rid of, then you need to examine Right( ret , 1)
and check, what is in there and replace that.