Support Forums

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.
User avatar
new_user
Posts: 157
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Tue Dec 31, 2013 2:44 pm

Yes please little lost why it works unless the description is pretty long. Thanks.
User avatar
jvierra
Posts: 9704
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Tue Dec 31, 2013 3:06 pm

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
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Wed Jan 01, 2014 9:19 pm

last
User avatar
jvierra
Posts: 9704
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Wed Jan 01, 2014 9:35 pm

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
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Thu Jan 02, 2014 6:57 am

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?
User avatar
jvierra
Posts: 9704
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Thu Jan 02, 2014 8:09 am

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.
User avatar
jvierra
Posts: 9704
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Thu Jan 02, 2014 8:14 am

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
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Thu Jan 02, 2014 9:24 am

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
User avatar
jvierra
Posts: 9704
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Description field line breaks when exporting in vbscript

Postby jvierra » Thu Jan 02, 2014 2:09 pm

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
Joined: Wed May 30, 2007 7:01 am

Re: Description field line breaks when exporting in vbscript

Postby new_user » Thu Jan 02, 2014 2:32 pm

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 339 times

Return to “VBScript”

Who is online

Users browsing this forum: No registered users and 2 guests