473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Importing CSV file to VB Script Array

I've been working on some coursework that requires the use of an excel
spreadsheet and a CSV file to be read into an ASP page and worked
with.

What I have done is set up an array to store the values from the CSV
file and accessed the spreadsheet using an Excel Recordset.

For some reason only the first 2 values in the CSV file (stored in the
array as the first and last) are comparing properly with values from
the spreadsheet.

When the comparisons are made I have used a loop to go through all the
records in the recordset and then another loop to search the array.
If I hard code the values instead of the array values the results are
as expected.

I've tried making sure all the values are trimmed and preceeded with
the "cstr" operation and still no joy. Even when I've written the
comparisons to screen it is saying "RGD11 = RGD11 = False"

Has any one got any clues as to what is going on???
Jul 19 '05 #1
2 14760
Michael Gooding wrote:
I've been working on some coursework that requires the use of an excel
spreadsheet and a CSV file to be read into an ASP page and worked
with.

What I have done is set up an array to store the values from the CSV
file and accessed the spreadsheet using an Excel Recordset.

For some reason only the first 2 values in the CSV file (stored in the
array as the first and last) are comparing properly with values from
the spreadsheet.

When the comparisons are made I have used a loop to go through all the
records in the recordset and then another loop to search the array.
If I hard code the values instead of the array values the results are
as expected.

I've tried making sure all the values are trimmed and preceeded with
the "cstr" operation and still no joy. Even when I've written the
comparisons to screen it is saying "RGD11 = RGD11 = False"

Has any one got any clues as to what is going on???


No. We're going to need to see some code, along with the sample data that
generates the error.

Bob Barrows
Jul 19 '05 #2

Reading CSV File into array:

csv_to_read="book1.csv"
set fso = createobject("scripting.filesystemobject")
set act = fso.opentextfile(server.mappath(csv_to_read))
imported_text = act.readline
imported_text = replace(imported_text,chr(13),",")
imported_text = replace(imported_text,chr(34),"")
split_text=split(imported_text,",")
num_imported=ubound(split_text)+1
total_imported_text = act.readall
total_imported_text = replace(total_imported_text,chr(13),",")
total_imported_text = replace(total_imported_text,chr(34),"")
total_split_text=split(total_imported_text,",")
total_num_imported=ubound(total_split_text)
Set cnnExcel = Server.CreateObject("ADODB.Connection")
sspath = "c:/website/comp/cz/xxxx/resources/test1.xls"

cnnExcel.Open "DBQ=" & sspath & ";" & "DRIVER={Microsoft Excel Driver
(*.xls)};"

counter = 0
for i = 0 to (total_num_imported - 1)
if i mod num_imported = 0 then
pinstore(counter) = total_split_text(i)
counter = counter + 1
end if

next
for i = 0 to (num_imported -1)
if i mod num_imported = 0 then
pinstore(counter) = split_text(i)
counter = counter + 1
end if

next
Connecting to excel spreadsheet:

Set cnnExcel = Server.CreateObject("ADODB.Connection")
sspath = "c:/website/comp/cz/xxxx/resources/test1.xls"
cnnExcel.Open "DBQ=" & sspath & ";" & "DRIVER={Microsoft Excel Driver
(*.xls)};"

Setting excel recordset:

Set rstExcel = Server.CreateObject("ADODB.Recordset")
q = "SELECT * FROM TestData where relationship <> 'SELF' and Name =" &
replace((request("name")),"_"," ") & ";"
rstExcel.Open q, cnnExcel, adOpenStatic, adLockPessimistic

Comparing values within a loop:

rstExcel.Open q, cnnExcel, adOpenStatic, adLockPessimistic
rstExcel.MoveFirst

' Loop through the data rows showing data in an HTML table.
step3 = 0
Do until rstExcel.EOF
Response.Write "<tr bgcolor='#EEEEEE'>" & vbCrLf
For I = 0 To iCols - 1
response.write icols & " I = " & I & "<br>"
column = I mod(icols)
select case column
case 0

case 1

Response.Write "<td>" & rstExcel.Fields.Item(I).Value & "</td>"
case 2
Response.Write "<td>" & rstExcel.Fields.Item(I).Value & "</td>"
case 3
Response.Write "<td>" & rstExcel.Fields.Item(I).value & "</td>"
case 4
Response.Write "<td>" & rstExcel.Fields.Item(I).Value & "</td>"
case 5

completed = false
for pincount = 0 to counter - 1

if rstexcel.fields.item(I-2).value = pinstore(pincount) then
completed = true
end if
next
if completed = true then
Response.Write "<td>Yes</td>"
else
Response.Write "<td><font color='#FF0000'>No</font></td>"
end if
end select

Next 'I
Response.Write "</tr>" & vbCrLf

rstExcel.MoveNext
Loop

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andreas Emmert | last post by:
Hi there, I'm trying to import a csv file into my MySQL database. Unfortunately the number format for the price column is formatted in German style, i.e. XX,XX (decimals separated by comma not...
2
by: Eric Linders | last post by:
Hello, The code below is used to grab each row from a CSV file (except the first row) and insert it into a database, as long as it's not already in the DB. If I echo each row's data, it...
1
by: J. Kenney | last post by:
Good Morning, Is there a way for a function called within an _imported_ library to call back to _calling_ python program to run a function? (Shown below) Also can you overload the print...
1
by: Matt Breedlove | last post by:
Ok, I dont see why this is so difficult, but it seems like all the solutions I have researched require me to identify each incoming variable which is very undesirable as there are 80+ hashes and...
3
by: George Yeh | last post by:
Hi There! Currently I am importing a .csv file that eventually grows over time. I have setup my table with an unique id field that is the primary key and indexed. I have also indicated in the...
29
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using...
5
by: BeruthialsCat | last post by:
First go with trying to import xml to a database and whilst i have managed to do what i want i find that the xml files we have here at work are gonna cause me problems. I have a function that...
4
toxicpaint
by: toxicpaint | last post by:
Hi there. I'm doing a job in a content management system and the controlling buggers censer anything after <script so, for example, if I want to import a js file and type <script...
1
by: Rahul | last post by:
What's a good way of importing a csv text file of floats into a Numeric array? I tried the csv module and it seems to work well so long as I've ints. Does anyone have any suggestions / snippets...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.