Description field line breaks when exporting in vbscript

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

Yes please little lost why it works unless the description is pretty long. Thanks.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

If I do this repeatedly:
a = 1
a = 2
a = 3
a = 4

What would you expect the final value of "a" to be?
User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

last
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

So in your script you should expect only the last value. That is why we wuld catenate the values.
User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

The does not match up to the output I see. The description field is multi-valued and it pulls the entire description, in only certain instances where the description happens to be over x characters does it break to a new line when writing the output. Guess I am missing something. That same function I use, and so do others, and never see an issue, wouldn't I if it were incorrect, if i were not concatenating it?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

You are assigning the description to a variable. The d3escripton is more than one line in many cases. If there is more than one lone assignment will give only the last line which may even be blank. Any multiline will not give you output to a file so it will appear to be blank.

Ther are two ways to "cat" or catentate an array. One is to use the 'Join" operator>

x = Join(myarray, "|")

The other is to enumerate the elements and catenate then with string operators;

x = x & item

"&" is the string concatenation operator.

It just hit me that you do not speak English as a first language so here are some translations for catenate:

spanish: encadenar
german: verketten
french: enchaîner


VB has the "Join" function which is misleading because "join" does not mean specifically to "catenate". It also adds a selectable piece into the catenation.

What we want is an end to end catenation. Some call that concatenating which is a redundant word in my opinion and seems awkward. The computer term has been "cat" for decades.

Some think of it as adding strinsggs to gether but that is not really what is happening.

The following will not cat these two items:

x = "1234" + 1
MsgBox x


The following will:

x = "1234" & 1
MsgBox x


The "&" is the string operator for catenation in VB languages. The + is addition. It will not correctly catenate strings in most cases if some objects are not strings. Since all variable look the same from the outside the + operator cannot be relied on to function as expected. VB adds the "&" to help solve this problem.


So in your loop try catenating the pieces of the array and you will get the whole description.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

Catenating in VBScript:
VBScript Code
Double-click the code block to select all.
' ways of catenating
a = Array("Hello","World","!")
MsgBox Join(a,"|")

For Each s In a
    x = x & s
Next
MsgBox x

a = "Hello"
MsgBox a

'this will cause an error
MsgBox Join(a,"|")
User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

Changed the function to the below with same result.

arrDesc = adoRecordSet.Fields("description").Value


' The description attribute is multi-valued, but
' there is never more than one item in the array.
arrDesc = adoRecordset.Fields("description").Value
If IsNull(arrDesc) Then
strDisplayDescription = ""
Else
For Each strValue In strDescription
strDisplayDescription = strDisplayDescription & strValue
Next
End If
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Description field line breaks when exporting in vbscript

Post by jvierra »

I have no idea why because I cannot see all of your code.

Change this line:
strDisplayDescription = strDisplayDescription & strValue
to:
WScript.Echo "DESC:" & strValue

See what you get.
User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Re: Description field line breaks when exporting in vbscript

Post by new_user »

When I did that it does not output any of the description field. I made a grammar change to a few variables and attached the code. Obviously I am missing something here. Thank you.
Attachments
Document7.txt
(5.71 KiB) Downloaded 559 times
This topic is 10 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked