Long variable write to file
i have a vbscript which connects to db2 and recset gets long varchar 18000 (contains xml message). The problem is that variable in vbscript has length only 250. Ok, i have divided recset to array(50) 250 chars each string. Then when i trying to pass first string from array to file it throws error. Because in array(0) string there are a lot of quotes. How can i save result to file?
sql = "select message_data from messages where MESSAGE_ID = '5461654648464'"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = "Provider=ibmdadb2; DSN=TEST; UID=user; PWD=password"
objConnection.Open
Set recset = CreateObject("ADODB.Recordset")
recset.Open sql,objConnection
if recset.EOF then WScript.Echo "No found" else splt recset("message_data") end if
recset.Close
objConnection.Close
function splt (strg)
dim arr(50)
Set fso = CreateObject("Scripti开发者_StackOverflowng.FileSystemObject")
sFolder = "C:\jdk1.3\temp\arch"
Set NewFile = fso.CreateTextFile(sFolder&"\file.txt", True)
if len(strg) > 250 then ll = round(len(strg)/250, 0) + 1
for i = 0 to ll
arr(i) = left(right(strg, abs(Cint(len(strg))-250*i)), 250)
txt = arr(i)
NewFile.Write txt
next
NewFile.Close
End function
@Ruslan: Make sure the file exists first (it can be just a blank text file) and I'd suggest you also update your function with
Dim arr(50), fso, sFolder, NewFile, ll, txt, i
and add Option Explicit
right at the top of the file as well.
精彩评论