CSV files into VB Arrays in ASP

M

Michael Gooding

Can anyone tell me why when using a .csv file called book1.csv with the
values below the code below does not recognise values read in after the
first line in a loop.

please feel free to run the code to see what I mean:

book1.csv:

RGB01,1,2,3,4
RGB02,1,2,3,4
RGB03,1,2,3,4
RGB04,1,2,3,4


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>


<%
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)



dim pinstore(500)
Dim I
Dim iCols

counter = 0

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


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

for i = 0 to counter -1
response.write pinstore(i) & " Is in the list<br>"

if pinstore(i) = "RGB01" then
response.write Pinstore(i) & " = Matched<p>"
end if
if pinstore(i) = "RGB02" then
response.write Pinstore(i) & " = Matched<p>"
end if
if pinstore(i) = "RGB03" then
response.write Pinstore(i) & " = Matched<p>"
end if
if pinstore(i) = "RGB04" then
response.write Pinstore(i) & " = Matched<p>"
end if
next


%>

</body>
</html>
 
R

Ray at home

It appears that split_text is an array created from act.readLINE, so you're
only going to get the first line in there. Maybe you meant to use
total_split_text.

Ray at home
 
L

Lance Wynn

imported_text = act.readline

tells it to read just one line, and move the pointer to the beginning of the
next line.

it looks like you need to enclose that whole thing in a loop until you reach
the end of the file. Or you can do ReadAll to read the entire contents of
the file into your string variable.





Can anyone tell me why when using a .csv file called book1.csv with the
values below the code below does not recognise values read in after the
first line in a loop.

please feel free to run the code to see what I mean:

book1.csv:

RGB01,1,2,3,4
RGB02,1,2,3,4
RGB03,1,2,3,4
RGB04,1,2,3,4


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>


<%
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)



dim pinstore(500)
Dim I
Dim iCols

counter = 0

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


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

for i = 0 to counter -1
response.write pinstore(i) & " Is in the list<br>"

if pinstore(i) = "RGB01" then
response.write Pinstore(i) & " = Matched<p>"
end if
if pinstore(i) = "RGB02" then
response.write Pinstore(i) & " = Matched<p>"
end if
if pinstore(i) = "RGB03" then
response.write Pinstore(i) & " = Matched<p>"
end if
if pinstore(i) = "RGB04" then
response.write Pinstore(i) & " = Matched<p>"
end if
next


%>

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top