Hi, little experience with scripts. Trying to create a program that will take a csv file and convert it to a fixed txt file with user specified field lengths.
I'm not sure if the script will even work once I get beyond my error but I've been stuck on a "type mismatch error" on line 46 for a few days now and I've exhausted my google searches. Your help is appreciated. if I change line 46 to: "spacetoadd = 20-strlen" I do not get the error, but since I need to have the variable spacetoadd equal the desired field size less the length of the current field, I can't use a constant value like 20.
here is my code: (any other suggestions or tips will also be appreciated)
cnt = 1
'Asks the user to type the message
strFilename = InputBox("What is the csv filename that you are converting:","Messenger Service", strFilename)
inputFile = strFilename & ".csv"
outputFile = strFilename & ".txt"
If strFilename = "" Then
Wscript.Echo "Operation canceled by the user"
strNumfields = InputBox("How many fields are in file?","Messenger Service", strNumfields)
strPos = InputBox("what are the field Lenghts seperate with comma?","Messenger Service", strPos)
dim arrStr, strMessage, spacetoadd, fieldSizes, strlen, asize
intSize = 0
spacetoadd = 0
fieldSizes = 0
fieldSizes = CLng(fieldSizes)
strlen = 0
asize = 0
Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile(outputFile,2,true)
set objTextFile = fs.OpenTextFile(inputFile)
Wscript.Echo "INput file:" & inputFile
Wscript.Echo "Output file:" & outputFile
'set objTextFile = fs.OpenTextFile("testconv100.csv")
Do while NOT objTextFile.AtEndOfStream
'ReDim Preserve arrStr(intSize)
fieldSizes = (Split(strPos, ","))
For h = LBound(fieldSizes) to UBound(fieldSizes)
asize = fieldSizes
'Wscript.Echo "lenght of field1 = " & str0len
arrStr = split(objTextFile.ReadLine,",")
For i = LBound(arrStr) to UBound(arrStr)
strlen = len(arrStr(i))
'Wscript.Echo "in the read line for loop, strlen = " & strLen & "," & spacetoadd & "," & asize
spacetoadd = asize-strlen
'Window.returnvalue = spacetoadd
field = field & arrStr(i)
field = field & space(spacetoadd)
Wscript.Echo "field =" & field
'outputString = (field0 & field1 & field2 & field3 & field4 & field5)
outputString = field
field = ""
cnt = cnt + 1
set objTextFile = Nothing
set fs = Nothing
Wscript.Echo "Total Record Count:" & cnt