From: Odd on 9 Sep 2009 09:51 On Sep 9, 9:21 am, Odd <audrey....(a)gmail.com> wrote: > On Sep 9, 3:36 am, "ekkehard.horner" <ekkehard.hor...(a)arcor.de> wrote: > > > > > > > Odd schrieb: > > [...] > > > > Ok I tried it. It seems to be ok. How would I output all of this to a > > > text file?? > > > Const adClipString = 2 ' 00000002 > > Const csSep = "," > > > Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" ) > > Dim sDDir : sDDir = oFS.GetAbsolutePathName( ".\adotext" ) > > Dim sTFName : sTFName = "Project_test.csv" > > Dim sFSpec : sFSpec = oFS.BuildPath( sDDir, sTFName ) > > Dim oADOCN : Set oADOCN = CreateObject( "ADODB.Connection" ) > > Dim sCS : sCS = Join( Array( _ > > "Provider=MSDASQL" _ > > , "Driver={Microsoft Text Driver (*.txt; *.csv)}" _ > > , "DBQ=" & sDDir ), ";" ) > > Dim sSQL : sSQL = "SELECT * FROM [" & sTFName & "]" > > > WScript.Echo "Working with", sFSpec > > WScript.Echo "Using CS", sCS > > WScript.Echo "SQL", sSQL > > > oADOCN.Open sCS > > Dim oRS : Set oRS = oADOCN.Execute( sSQL ) > > Dim sHead : sHead = "" > > Dim oFld > > For Each oFld In oRS.Fields > > sHead = sHead & csSep & oFld.Name > > Next > > sHead = Mid( sHead, 2 ) > > Dim sFAll : sFAll = oRS.GetString( adClipString, , csSep, vbLf, "" ) > > oRS.Close > > oADOCN.Close > > > Dim aRpl : aRpl = Array( vbTab, "", vbCrLf, "", vbLf, vbCrLf ) > > Dim nIdx > > For nIdx = 0 To UBound( aRpl ) Step 2 > > sFAll = Replace( sFAll, aRpl( nIdx ), aRpl( nIdx + 1 ) ) > > Next > > > Dim oRE : Set oRE = New RegExp > > oRE.Global = True > > oRE.Pattern = " +" > > sFAll = oRE.Replace( sFAll, " " ) > > > sFAll = sHead & vbCrLf & sFAll > > > WScript.Echo sFAll > > > Dim dtNow : dtNow = Date > > sFSpec = "Project_" & Year( dtNow ) & Right( 100 + Month( dtNow ), 2 ) & Right( 100 + > > Day( dtNow ), 2 ) & ".csv" > > oFS.CreateTextFile( oFS.BuildPath( sDDir, sFSpec ), True ).Write sFAll > > > output: > > > === EmbeddedLineEndings: how to deal with embedded line endings =============== > > Working with C:\wis\_vbs\0506\dev\forum\adotext\Project_test.csv > > Using CS Provider=MSDASQL;Driver={Microsoft Text Driver (*.txt; > > *.csv)};DBQ=C:\wis\_vbs\0506\dev\forum\adotext > > SQL SELECT * FROM [Project_test.csv] > > Project_ID,Project_Name,High_Level_Outline,Project_Currency_ID > > 5,ProjectA,TBD,2 > > 7,ProjectB,TBD,2 > > 24,ProjectC,TBD,2 > > 41,ProjectE,Eliminate the use of Returned ItemEliminate the use of Returned > > ItemCreation of a new electronic meansCreation of a new database inte > > rnal applications onlyAddition of new return,2 > > 46,ProjectG,TBD,2 > > > === EmbeddedLineEndings: 0 done (00:00:01) ==================================== > > Hi, > > I copy and pasted the code and ran it. Nothing happened. The > Project_Test.csv file is under D:\Test\adotext and the script is under > D:\Test. > > Please advise.- Hide quoted text - > > - Show quoted text - It's ok. I got it. |