473,473 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CSV files into VB Arrays in ASP

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>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
2 4146
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.

"Michael Gooding" <mi*************@etsplc.com> wrote in message
news:e7**************@TK2MSFTNGP10.phx.gbl...
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>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #2
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

"Michael Gooding" <mi*************@etsplc.com> wrote in message
news:e7**************@TK2MSFTNGP10.phx.gbl...
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.

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


Jul 19 '05 #3

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

Similar topics

18
by: xarax | last post by:
Greetings, What is the general practice, usual and customary way, of including a data file into a source file? I have some large data structures defined as source similar to: ...
2
by: David | last post by:
Hi all, I am fairly new to C#. so go easy on me :-) Anyhow, I have a class file that I have set up properties and a method. I am calling this class file directly from and aspx.cs file. So...
8
by: Frost | last post by:
Hi All, I am a newbie i have written a c program on unix for line by line comparison for two files now could some one help on how i could do word by word comparison in case both lines have the...
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
10
by: Tammy | last post by:
Hello all, I am wondering what is the best way to declare a struct to be used in other c and c++ files. Such as for a C API that will be used by others. 1. Declaring the typedef and the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.