Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 01-05-2009
Member
 
Join Date: Feb 2009
Posts: 20
Remove new line from vbscript

Hi GUys,

From my vbs code it write the empty next line which i don't want it. Appreciate any of yours can see my code if there is a syntax ERROR that creating a new next line when i write into .csv file

book.cvs file example:
DN,name,title,office
"CN=th, DC=dsa, MY=jsda",yew,VP,raja laut
"CN=th1, DC=dsa, MY=jsda",yew1,VP,raja laut
"CN=th2, DC=dsa, MY=jsda",yew2,VP,raja laut
"CN=th3, DC=dsa, MY=jsda",yew3,VP,raja laut
"CN=th, DC=dsa, MY=jsda",yew,VP,raja laut

Result I get is below but i dont want a empty line space at each line:
name,title,office
yew,VP,raja laut

yew1,VP,raja laut

yew2,VP,raja laut

yew3,VP,raja laut

yew,VP,raja laut


My code example:
Dim objFSO, dataArray, clippedArray1(), clippedArray2()
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Create an array out of the CSV
'open the data file
Set oTextStream = objFSO.OpenTextFile("C:\book.csv")
Set newFile = objFSO.CreateTextFile("C:\newCSV.csv")
'make an array from the data file
dataArray = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close

x = 0
For Each strLine In dataArray
'Get first character
Call FirstAlign()
Next

Function FirstAlign()
'Now make an array from each line of dataArray
ReDim Preserve clippedArray1(x)
clippedArray1(x) = Split(strLine,",")
CutColumn = 0
intCount = 0
newLine = ""
For Each Element1 In clippedArray1(x)
If intCount = UBound(clippedArray1(x)) Then
EndChar = vbCrLf
Else
EndChar = ","
End If

If intCount <> CutColumn Then
newLine = newLine & Element1 & EndChar
End If

intCount = intCount + 1
If intCount = UBound(clippedArray1(x))+1 Then
'Before write into a line check and do second filtering of first Column
IntCheck = InStr(newLine, chr(34))
If IntCheck <> 0 Then
Call SecondAlign(newLine)
Else
newFile.Write newLine
End If
End If
Next
End Function


Function SecondAlign(strLine2)
ReDim Preserve clippedArray2(x)
clippedArray2(x) = Split(strLine2,chr(34))
CutCol = 0
intCnt = 0
secLine = ""
For Each Element2 In clippedArray2(x)
If intCnt = UBound(clippedArray2(x)) Then
EndChar2 = vbCrLf
Else
EndChar2 = ","
End If

If intCnt <> CutCol Then
secLine = secLine & Element2 & EndChar2
End If

intCnt = intCnt + 1
If intCnt = UBound(clippedArray2(x))+1 Then
secLine = Mid(secLine, 2, Len(secLine))
newFile.Write secLine
End If
Next
End Function
Reply With Quote
  #2  
Old 01-05-2009
Member
 
Join Date: May 2008
Posts: 945
Re: Remove new line from vbscript

Quote:
dataArray = Split(oTextStream.ReadAll, vbNewLine)
and
Quote:
EndChar = vbCrLf
I suppose don't use vbNewLine and vbCrLf because they both will feed that output with the new line (which is your problem). Since you are using both, the output that you are getting have extra lines. I hope I was clear.
Reply With Quote
  #3  
Old 02-05-2009
Member
 
Join Date: Feb 2009
Posts: 20
Re: Remove new line from vbscript

Quote:
Originally Posted by Lemog View Post
and


I suppose don't use vbNewLine and vbCrLf because they both will feed that output with the new line (which is your problem). Since you are using both, the output that you are getting have extra lines. I hope I was clear.

Thank you Lemog,
It resolved by replacing EndChar = "". Good Job
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Remove new line from vbscript"
Thread Thread Starter Forum Replies Last Post
How to remove black horizontal line in openoffice Efrosini Windows Software 3 17-02-2012 04:55 PM
How to create ZIP Files from Command-Line via VBScript? FB Windows Server Help 10 22-12-2011 12:18 AM
How to remove leading whitespace from each line? Conraad Software Development 5 23-02-2010 10:14 PM
How to remove the blank line in excel? Rup_me Windows Software 5 16-12-2009 06:48 PM
How can I add a new line to vbscript? Baani Software Development 2 29-05-2009 04:54 PM


All times are GMT +5.5. The time now is 02:24 PM.