Welcome Guest. Please Login or Register


You are here: Index > mForm - User's Exchange > Form Processing and Servers > Topic : VB script to process cvs file



Threaded Mode | Print  

 VB script to process cvs file (0 Replies, Read 1917 times)
nogods
Group: Member
Post Group: Newbie
Posts: 1
Status:
Here is a link to a short microsoft Developers explanation and example script for processing a cvs file with a vbscript program using Microsoft ActiveX Database Objects (ADO) techniques.

http://msdn.microsoft.com/en-us/library/ms974559.aspx

It sounds complicated but it is really simple. The example code will work on any cvs file as long as you change:

1. the path to your file,

2. the file name (use a file name without spaces so you don't have to mess with quotations inside other quotations)

3. the field names you want to extract.


The example script displays the contents but it could easily be modified to store the contents into variables to be used to insert into another program.

Also, to get it to run I had to delete the first line ("On Error Resume Next") as vbscript kept telling me it was an invalid line.

here is the example script in case the link doesn't work:
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

strPathtoTextFile = "C:\Databases\"

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""

objRecordset.Open "SELECT * FROM PhoneList.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
Wscript.Echo "Name: " & objRecordset.Fields.Item("Name")
Wscript.Echo "Department: " & _
objRecordset.Fields.Item("Department")
Wscript.Echo "Extension: " & objRecordset.Fields.Item("Extension")
objRecordset.MoveNext
Loop

IP: --   


Threaded Mode | Print  



Users viewing this topic
1 guests, 0 users.


Powered By AEF 1.0.3 © 2006 Electron Inc.Queries: 10  |  Page Created In:0.040