473,326 Members | 2,732 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,326 software developers and data experts.

2D array help

hello,

im trying to write a script that will allow me to take names and addresses
from a coma delimetered text file and insert them into a db.

ive managed to come up with this script which deals with works well if i
only have names in the text file.

ie:

bob smith, peter smith, brian smith

but now i want to do something simular with a text file formatted like so

bob smith, bob smiths address, peter smith, peter smiths address,

i think i have to use a 2 demensional array but really have no idea how to
go about it. any help appreciated. here is what i have so far.

dim objConn, path
set objConn = server.createobject("ADODB.connection")
path = "C:\Inetpub\wwwroot\audiblefaction\snippets\test.m db"
objConn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & path & ";"
dim objFSO, objTextFile, strNextLine
set objFSO = createobject("scripting.filesystemobject")
set objTextFile =
objFSO.OpenTextFile("C:\Inetpub\wwwroot\audiblefac tion\snippets\test.txt",1)
do until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arr = split(strNextLine,",")
dim sql
for i = 0 to ubound(arr)
sql = "INSERT INTO table (column) VALUES ('" & arr(i) & "')"
on error resume next
objConn.execute(sql)
if err.number <> 0 then
response.write "an error has occurred....no data added<br>"
else
response.write arr(i) & " added.<br>"
end if
next
loop
objConn.close
set objConn = nothing
set objFSO = nothing
set objTextFile = nothing
Jul 19 '05 #1
2 1436
[ + 2 0 r p 3 ] wrote:
hello,

im trying to write a script that will allow me to take names and
addresses from a coma delimetered text file and insert them into a db.

ive managed to come up with this script which deals with works well
if i only have names in the text file.

ie:

bob smith, peter smith, brian smith

but now i want to do something simular with a text file formatted
like so

bob smith, bob smiths address, peter smith, peter smiths address,
You may have a problem: some addresses contain commas.

i think i have to use a 2 demensional array but really have no idea
how to go about it. any help appreciated. here is what i have so far..
No, you do not need a 2-dimensional array. See below for changes:
arr = split(strNextLine,",")
dim sql
for i = 0 to ubound(arr)
for i = 0 to ubound(arr) Step 2
sql = "INSERT INTO table (column) VALUES ('" & arr(i) & "')"

sql = "INSERT INTO table (column) " & _
" VALUES ('" & arr(i) & "', '" & arr(i+1) & "')"
response.write sql & "<BR>"
Comment out the response.write when you have the code working properly.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #2
thankyou muchly kind sir....works great! i know to be carefull with
addresses containing comas.

im off to take a look at how this skip 2 thing works.

thanks again

"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:eR*************@TK2MSFTNGP11.phx.gbl...
[ + 2 0 r p 3 ] wrote:
hello,

im trying to write a script that will allow me to take names and
addresses from a coma delimetered text file and insert them into a db.

ive managed to come up with this script which deals with works well
if i only have names in the text file.

ie:

bob smith, peter smith, brian smith

but now i want to do something simular with a text file formatted
like so

bob smith, bob smiths address, peter smith, peter smiths address,


You may have a problem: some addresses contain commas.

i think i have to use a 2 demensional array but really have no idea
how to go about it. any help appreciated. here is what i have so far..


No, you do not need a 2-dimensional array. See below for changes:
arr = split(strNextLine,",")
dim sql
for i = 0 to ubound(arr)


for i = 0 to ubound(arr) Step 2
sql = "INSERT INTO table (column) VALUES ('" & arr(i) & "')"

sql = "INSERT INTO table (column) " & _
" VALUES ('" & arr(i) & "', '" & arr(i+1) & "')"
response.write sql & "<BR>"
Comment out the response.write when you have the code working properly.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 19 '05 #3

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

Similar topics

8
by: point | last post by:
Hi there.. I have the folowing array => property = hexonet => property = 2003-12-01 18:46:20.0 => property = hexonet => property = 2003-12-02 02:59:15.0 => property = hexonet =>...
2
by: Antti Nummiaho | last post by:
Consider the following javascript: var temp = new Array(new Array(0)) document.writeln(temp) temp = new Array(new Array(0,1)) document.writeln(temp) One would assume that it would print "0...
8
by: Gactimus | last post by:
I made the program below. It outputs the smallest number in the array. What I would like to know is how do I output the array location. I am at a loss. For example, since the smallest number in...
7
by: ritchie | last post by:
Hi all, I am new to this group and I have question that you may be able to help me with. I am trying to learn C but am currently stuck on this. First of all, I have a function for each sort...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
5
by: fluk | last post by:
Hi Guys, I hope someone can help me with this, because i'm getting crazy to find a good way to do that! This is what I got by querying a db. $arr1 = array("site", "description", "area1" ,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.