IIS ASP - Delete ASP Multidimensional Array

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > March 2006 > Delete ASP Multidimensional Array





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Delete ASP Multidimensional Array

2006-03-25, 11:58 am

I'm fairly new to ASP and must admit its proving a lot more unnecessarily
complicated than the other languages I know. I feel this is because there
aren't many good official resources out there to help do the most basic
things.

One of the "basic" things I haven't been able to find out how to do is how
to delete an item from a multidimensional array object and resize it
afterwards.

It seems so easy to conceive of the code to delete from a multidimensional
array but it just isn't working. Surely it should be as easy as something
like:

myArray.delete(1,0)
myArray.remove(5,7)

but what it is and how to find out - there just doesn't seem to be a way. I
reckon there must have been some collusion going on between m$ and the
writers of books called things like "Learn ASP in 4 days!!!" to stifle the
spread of information in order to make money because this language is
unreal!


Slim

2006-03-25, 11:58 am

try
redim yourArray(5,5)

if you want to preserver the existing data

redim preserve yourArray(6,6)

this is all listed in the vbscript file


<nospam@nospam.com> wrote in message
news:peSdnRG1nckT-L_ZnZ2dnUVZ8qednZ2d@bt.com...
> I'm fairly new to ASP and must admit its proving a lot more unnecessarily
> complicated than the other languages I know. I feel this is because there
> aren't many good official resources out there to help do the most basic
> things.
>
> One of the "basic" things I haven't been able to find out how to do is how
> to delete an item from a multidimensional array object and resize it
> afterwards.
>
> It seems so easy to conceive of the code to delete from a multidimensional
> array but it just isn't working. Surely it should be as easy as something
> like:
>
> myArray.delete(1,0)
> myArray.remove(5,7)
>
> but what it is and how to find out - there just doesn't seem to be a way.
> I reckon there must have been some collusion going on between m$ and the
> writers of books called things like "Learn ASP in 4 days!!!" to stifle the
> spread of information in order to make money because this language is
> unreal!
>



Evertjan.

2006-03-25, 11:58 am

Xref: TK2MSFTNGP08.phx.gbl microsoft.public.inetserver.asp.general:303536

Slim wrote on 23 mrt 2006 in microsoft.public.inetserver.asp.general:
> <nospam@nospam.com> wrote in message
> news:peSdnRG1nckT-L_ZnZ2dnUVZ8qednZ2d@bt.com...
> try
> redim yourArray(5,5)
>
> if you want to preserver the existing data
>
> redim preserve yourArray(6,6)
>
> this is all listed in the vbscript file


The problem is, that ASP is not a language at all, but a platform for
serverside scripting languages, like vbscript and jscript.

It seems that you are both ignoring that and consequently don't connect.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Anthony Jones

2006-03-25, 11:58 am


<nospam@nospam.com> wrote in message
news:peSdnRG1nckT-L_ZnZ2dnUVZ8qednZ2d@bt.com...
> I'm fairly new to ASP and must admit its proving a lot more unnecessarily
> complicated than the other languages I know. I feel this is because there
> aren't many good official resources out there to help do the most basic
> things.
>
> One of the "basic" things I haven't been able to find out how to do is how
> to delete an item from a multidimensional array object and resize it
> afterwards.
>
> It seems so easy to conceive of the code to delete from a multidimensional
> array but it just isn't working. Surely it should be as easy as something
> like:
>
> myArray.delete(1,0)
> myArray.remove(5,7)
>
> but what it is and how to find out - there just doesn't seem to be a way.

I
> reckon there must have been some collusion going on between m$ and the
> writers of books called things like "Learn ASP in 4 days!!!" to stifle the
> spread of information in order to make money because this language is
> unreal!
>
>


ASP is essentially a scripting host with some ASP specific objects loaded
into the scripting context.

To use ASP you really need to look for documentation related not only to ASP
but also to the script language you are using.

Take look at these for documentation of the ASP objects

http://msdn.microsoft.com/library/e...1d97c2a08c2.asp

http://msdn.microsoft.com/library/e...ef33a651779.asp

Then take look at this if you are using Java script:-

http://msdn.microsoft.com/library/e...bbfe2330aa9.asp

Or this if vbscript :-

http://msdn.microsoft.com/library/e...65acb52fc54.asp

Given the choice I prefer Javascript but if you want to gather and use ASP
examples from around the web you might want to stick with VBScript.

Anthony.


Mike Brind

2006-03-25, 11:58 am


nospam@nospam.com wrote:
> I'm fairly new to ASP and must admit its proving a lot more unnecessarily
> complicated than the other languages I know. I feel this is because there
> aren't many good official resources out there to help do the most basic
> things.
>


Mistake number one - ASP is not a language. It's a technology. You
can access this technology using a number of different languages,
including JScript, Javascript, PERL and VBScript - the latter seems to
be the one used by the vast majority of developers.

When you search for code and help, I suggest you add the language you
are using for your scripts eg "VBScript arrays", and you shouldn't have
any problem getting help.

You might also like to download the language reference for VBScript
from Microsoft (it's free, by the way) here:
http://www.microsoft.com/downloads/...&DisplayLang=en

and then visit the official ASP documentation here:
http://msdn.microsoft.com/library/d...ef33a651779.asp

Good luck

--
Mike Brind

2006-03-25, 11:58 am

> try
> redim yourArray(5,5)


<%
Dim mycartArray
Redim mycartarray(1,1)
mycartArray(0,0) = "this"
mycartArray(0,1) = "that"
mycartArray(1,0) = "them"
mycartArray(1,1) = "those"
redim mycartArray(1,1)

Response.Write "<table><tr>"
Response.Write "<td bgcolor=#dddddd>00" & mycartArray(0,0) & "</td></tr>"
Response.Write "<td bgcolor=#dddddd>01" & mycartArray(0,1) & "</td></tr>"
Response.Write "<td bgcolor=#dddddd>10" & mycartArray(1,0) & "</td></tr>"
Response.Write "<td bgcolor=#dddddd>11" & mycartArray(1,1) & "</td></tr>"
Response.Write "</table>"
%>

Result:
00
01
10
11

> if you want to preserver the existing data
>
> redim preserve yourArray(6,6)


<%
Dim mycartArray
Redim mycartarray(1,1)
mycartArray(0,0) = "this"
mycartArray(0,1) = "that"
mycartArray(1,0) = "them"
mycartArray(1,1) = "those"
redim preserve mycartArray(1,1)

Response.Write "<table><tr>"
Response.Write "<td bgcolor=#dddddd>00" & mycartArray(0,0) & "</td></tr>"
Response.Write "<td bgcolor=#dddddd>01" & mycartArray(0,1) & "</td></tr>"
Response.Write "<td bgcolor=#dddddd>10" & mycartArray(1,0) & "</td></tr>"
Response.Write "<td bgcolor=#dddddd>11" & mycartArray(1,1) & "</td></tr>"
Response.Write "</table>"
%>

Result:
00this
01that
10them
11those

I'm sorry to be thick but how is this deleting or preserving what I need it
to? I want to clear item (1,1) of the value "those" and retain all the other
information in the array.

> this is all listed in the vbscript file
>
>
> <nospam@nospam.com> wrote in message
> news:peSdnRG1nckT-L_ZnZ2dnUVZ8qednZ2d@bt.com...
>
>



2006-03-25, 11:58 am

> You might also like to download the language reference for VBScript
> from Microsoft (it's free, by the way) here:
> http://www.microsoft.com/downloads/...&DisplayLang=en


Arrgh! I'm really not having any luck here. I followed your link and it was
just the lastest scripting installation package - no docs or help concerning
where it may or may not have installed any docs. But I found a link from
that page which was for the documentation I think you mean to link me to and
then when I downloaded that it looked excellent but the first page I was
greeted with was page cannot be displayed and none of the other references
go anywhere or do anything (and I took my firewall off temporarily to work
out why its not loading).

> and then visit the official ASP documentation here:
> http://msdn.microsoft.com/library/d...ef33a651779.asp
>
> Good luck


Thanks - I'm gonna need it..


Slim

2006-03-25, 11:58 am


<nospam@nospam.com> wrote in message news:8dydnRqQh73J6b_ZRVnyvw@bt.com...
>
> <%
> Dim mycartArray
> Redim mycartarray(1,1)
> mycartArray(0,0) = "this"
> mycartArray(0,1) = "that"
> mycartArray(1,0) = "them"
> mycartArray(1,1) = "those"
> redim mycartArray(1,1)
>
> Response.Write "<table><tr>"
> Response.Write "<td bgcolor=#dddddd>00" & mycartArray(0,0) & "</td></tr>"
> Response.Write "<td bgcolor=#dddddd>01" & mycartArray(0,1) & "</td></tr>"
> Response.Write "<td bgcolor=#dddddd>10" & mycartArray(1,0) & "</td></tr>"
> Response.Write "<td bgcolor=#dddddd>11" & mycartArray(1,1) & "</td></tr>"
> Response.Write "</table>"
> %>
>
> Result:
> 00
> 01
> 10
> 11
>
>
> <%
> Dim mycartArray
> Redim mycartarray(1,1)
> mycartArray(0,0) = "this"
> mycartArray(0,1) = "that"
> mycartArray(1,0) = "them"
> mycartArray(1,1) = "those"
> redim preserve mycartArray(1,1)
>
> Response.Write "<table><tr>"
> Response.Write "<td bgcolor=#dddddd>00" & mycartArray(0,0) & "</td></tr>"
> Response.Write "<td bgcolor=#dddddd>01" & mycartArray(0,1) & "</td></tr>"
> Response.Write "<td bgcolor=#dddddd>10" & mycartArray(1,0) & "</td></tr>"
> Response.Write "<td bgcolor=#dddddd>11" & mycartArray(1,1) & "</td></tr>"
> Response.Write "</table>"
> %>
>
> Result:
> 00this
> 01that
> 10them
> 11those
>
> I'm sorry to be thick but how is this deleting or preserving what I need
> it to? I want to clear item (1,1) of the value "those" and retain all the
> other information in the array.



ok
mycartArray(1,1) = ""




>
>
>



Bob Barrows [MVP]

2006-03-25, 11:58 am

nospam@nospam.com wrote:
>
> Arrgh! I'm really not having any luck here. I followed your link and
> it was just the lastest scripting installation package - no docs or help
> concerning where it may or may not have installed any docs. But I found a
> link
> from that page which was for the documentation I think you mean to link me
> to and


Was it this link?
http://www.microsoft.com/downloads/...&displaylang=en

> then when I downloaded that it looked excellent but the first page I
> was greeted with was page cannot be displayed and none of the other
> references


Where did you install it? I've seen that in certain cases where I didn't
install the chm file to my local hard drive.

You can read the vbscript docs online at
http://msdn.microsoft.com/library/e...65acb52fc54.asp

This will be the same documentation that is included in the download in the
previous link.
In addition, you will find documentation for all MS developer technologies
at this website.

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"


Anthony Jones

2006-03-25, 11:58 am


>One of the "basic" things I haven't been able to find out how to do is how
>to delete an item from a multidimensional array object and resize it
>afterwards.


Using any syntax of any language with which you are currently familiar can
you post the code that would do this "basic" thing?

It's fairly easy to set the contents of an array element to a null or empty
value but I suspect what you really want to do is destroy the 'cell'
completely, moving all other cells up some how. You haven't specified how
exactly though.

For example in a 3x3 matrix if item(0,1) is destroyed does item(1,0) become
item(0,2)?

Anthony.


Bob Barrows [MVP]

2006-03-25, 11:59 am

nospam@nospam.com wrote:
> I'm fairly new to ASP and must admit its proving a lot more
> unnecessarily complicated than the other languages I know. I feel
> this is because there aren't many good official resources out there
> to help do the most basic things.
>
> One of the "basic" things I haven't been able to find out how to do
> is how to delete an item from a multidimensional array object and
> resize it afterwards.
>
> It seems so easy to conceive of the code to delete from a
> multidimensional array but it just isn't working. Surely it should be
> as easy as something like:
>
> myArray.delete(1,0)
> myArray.remove(5,7)
>


In whatever language you are used to using, this must be an easy task. It
sounds as if arrays in that language behave more like what would be called
"collection" in VB. With a collection, items can be removed from or inserted
into the "middle" of the collection. What I am going to talk about applies
to VB, VBA and vbscript, so for simplicity's sake, I am going to refer
simply to "VB" in the following.

With VB arrays, this is not possible. In VB, arrays are "simple" structures
that have no methods for manipulating them such as would be found with a
collection class. VB provides these statements for dealing with arrays
Dim ar([upper index][,...n]): initializes the variable. If an upper index
value is supplied, a fixed-size array is created. If no upper index is
provided, a dynamic array is created (this applies to vbscript - in VB, more
options exist)
ReDim [Preserve]: used to modify an existing array. If used without the
Preserve keyword, all the data in the array is clearedIt can only be used to
change the index of the last dimension in a multi-dimensional array.. In
addition, Preserve will only work when the last dimension in an array is
modified:

dim ar(1,1)
....
redim preserve ar(1,2) ' preserves existing data
redim preserve ar(1,0) 'removes last "row", preserves first "row"
redim preserve ar(2,2) ' clears all existing data (may return error)

Erase: "Reinitializes the elements of fixed-size arrays and deallocates
dynamic-array storage space"

In addition, the following functions exist:
Array(item1,...,itemN): "Returns a Variant containing an array"
LBound(array,[dimension number]): Returns the lowest bound (available
subscript) of the specified array's dimension - not useful in vbscript where
the lowest bound of an array's dimension is always 0
UBound(array,[dimension number]): Returns the upper bound (highest available
subscript) of the specified array's dimension

That's it. This is all you have to work with to manipulate arrays.

So, all you can do is

1. Modify the content of an array element
ar(1,1) = "this"
ar(1,1) = ""

2. Add new elements to the end of a dynamic array:
dim ar()
redim ar(0)
ar(0)="this"
redim preserve ar(1)
ar(1)="that"
Note: ReDim is an "expensive" operation. If you know how many elements will
be needed, you should resize the array in a single statement. Avoid using
redim in a loop:
dim ar()
for i =0 to 3
redim preserve ar(i)
ar(i) = i
next

Instead, do this:
dim ar()
'figure out what the upper bound should be, then
redim ar(3)
for i = 0 to 3
ar(i) = i
next

3. Remove elements from the end of the array (see above)

If you need to be able to remove elements from the middle of an array, you
have to write your own method to do that. Something like:

Sub RemoveAt(ByRef ar, index)
for i = index to ubound(ar) - 1
ar(i) = ar(i+1)
next
redim preserve ar(ubound(ar,1) - 1)
end sub

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com