Forums

ASP

This topic is locked

Using fields as an array

Posted 20 Jul 2001 15:00:06
1
has voted
20 Jul 2001 15:00:06 Bec C posted:
How do I use an Access field as an array that can hold many values e.g. a friends contact list for my forum pages I am building?

field friendsList = friend1, friend2 etc

How do I use VB to get at the field in this way so each comman-sep. entry is a separate value?

Thanks

Replies

Replied 20 Jul 2001 16:12:08
20 Jul 2001 16:12:08 Joel Martinez replied:
that's an easy one... just make the field a memo datatype (so you don't have to worry about size)
and enter the values as comma separated values.

to enter new values, just do an update like this:
<pre id=code><font face=courier size=2 id=code>UPDATE table
SET contacts = contacts + ',' + mmParam1
WHERE whatever = MMwhatever</font id=code></pre id=code>

then to read the values into an array, just get the recordset, and do this :
<pre id=code><font face=courier size=2 id=code>cArray = split(rs.fields("contacts".value, ","</font id=code></pre id=code>

and boom, you've got an array that you can loop through...

Joel Martinez

----------
Is this thing on?....
Replied 20 Jul 2001 16:37:26
20 Jul 2001 16:37:26 George Petrov replied:
or you use the ADo call:
<pre id=code><font face=courier size=2 id=code>rsMyData.GetRows()</font id=code></pre id=code>
This will return all records in a array - with as many dimentions as you have fields in the recordset.

---------------------------------------
George Petrov - CTO, www.UDzone.com

www.UDzone.com : A Dreamweaver,
Dreamweaver Ultradev and Fireworks site
by developers for developers.
---------------------------------------

Replied 24 Jul 2001 17:29:57
24 Jul 2001 17:29:57 Bec C replied:
Thanks for the code.

I have tried the code and I get this message appear:

Response object error 'ASP 0106 : 80020005'

Type Mismatch

?

An unhandled data type was encountered.

I was using &lt;% = cArray %&gt; to display the record. IS this the wrong way?!?

Thanks
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
that's an easy one... just make the field a memo datatype (so you don't have to worry about size)
and enter the values as comma separated values.

to enter new values, just do an update like this:
<pre id=code><font face=courier size=2 id=code>UPDATE table
SET contacts = contacts + ',' + mmParam1
WHERE whatever = MMwhatever</font id=code></pre id=code>

then to read the values into an array, just get the recordset, and do this :
<pre id=code><font face=courier size=2 id=code>cArray = split(rs.fields("contacts".value, ","</font id=code></pre id=code>

and boom, you've got an array that you can loop through...

Joel Martinez

----------
Is this thing on?....
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Replied 24 Jul 2001 19:03:21
24 Jul 2001 19:03:21 Joel Martinez replied:
hmm, that error would happen if you are trying to display the cArray variable when it's an array...
once you run the split command on the field, it's an array, which means that you'd have to access the values like this:
<pre id=code><font face=courier size=2 id=code>&lt;%=cArray(0)%&gt;</font id=code></pre id=code>
of course, you'll never know how many fields is in the array, so you can do some sort of loop like this:
<pre id=code><font face=courier size=2 id=code>max = ubound(cArray,1)
for i=0 to max

response.write cArray(i) & "&lt;br&gt;"

next</font id=code></pre id=code>
of course, that would only list the items of the array like this
item1
item2
item3
item4

you'll have to format it to your purposes...

Joel Martinez

----------
Is this thing on?....

Reply to this topic