Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do arrays work?

Posted on 2003-03-20
8
Medium Priority
?
2,918 Views
Last Modified: 2012-06-21
Hello,

I'm having big problems with arrays in asp. What I would like to know is how to assign an array to another array? In my example both arrays are of the same dimension and I still get an error! Could anyone tell me what I am doing wrong here?

<%
 Dim A(1,1)
 Dim B(1,1)
 
 B(0,0) = "A"
 B(0,1) = "B"
 B(1,0) = "C"
 B(1,1) = "D"
     Response.Write("B(0,0) = " & B(0,0) & "<br>")
     Response.Write("B(0,1) = " & B(0,1) & "<br>")
     Response.Write("B(1,0) = " & B(1,0) & "<br>")
     Response.Write("B(1,1) = " & B(1,1) & "<br>")
 A(0,0) = "D"
 A(0,1) = "C"
 A(1,0) = "B"
 A(1,1) = "A"
     Response.Write("A(0,0) = " & A(0,0) & "<br>")
     Response.Write("A(0,1) = " & A(0,1) & "<br>")
     Response.Write("A(1,0) = " & A(1,0) & "<br>")
     Response.Write("A(1,1) = " & A(1,1) & "<br>")
 
A=B
%>

What I get in IE 6 is:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
/test/test.asp, line 55 ---> this is line where I assign B to A (A=B)

thanks and best regards,
U.
0
Comment
Question by:uipavec
8 Comments
 
LVL 11

Expert Comment

by:ASPGuru
ID: 8174693
you can't assign anything to an variable which was dimed as an array...

you need to copy every value "by hand" ...

or use this sub (arrays need to have the same size, or the size of the first Array needs to be smaller in every dimension)

Array2DCopy A, B

sub Array2DCopy(ByRef A1, ByRef A2)
  dim i,j
  for i = 0 to ubound(A1,1)
    for j = 0 to ubound(A2,2)
      A1(i,j) = A2(i,j)
    next
  next
end sub


ASPGuru
0
 
LVL 7

Expert Comment

by:chisholmd
ID: 8174789
You can assign to another variable:

Dim A(1,1)
B(0,0) = "A"
B(0,1) = "B"
B(1,0) = "C"
B(1,1) = "D"
A=B

should work:

Also you might be able to do this
Dim A(1,1)
Dim B(1,1)
B(0,0) = "A"
B(0,1) = "B"
B(1,0) = "C"
B(1,1) = "D"
A(0,0) = "D"
A(0,1) = "C"
A(1,0) = "B"
A(1,1) = "A"

A=""
A=B

dave

0
 
LVL 11

Expert Comment

by:ASPGuru
ID: 8175007
might doesn't mean it does... ;-)

ASPGuru
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Expert Comment

by:chisholmd
ID: 8175139
Ya :)  bit sloppy eh?

Pretty sure that I have done that in one project but can't remember which.  However I think I do this:

dim someArr(1)
someArr(0) = "blah"
someArr(0) = "blahblah"

newArray = someArray
newArray = ""
newArray = someOtherArray

Which is not exactly the same because I never dim the newArray.
0
 
LVL 11

Expert Comment

by:ASPGuru
ID: 8175192
that's right... this works...
because you never dim...

but this doesn't copy anything...
this just sets a pointer to the old array... if you change something in newArray it will also change in someArr...


regards,

ASPGuru
0
 
LVL 5

Accepted Solution

by:
dgorin earned 200 total points
ID: 8175421
This will work to copy array A to array B.

<%@ Language=VBScript %>
<%
Dim A(1,1)
Dim B

A(0,0) = "D"
A(0,1) = "C"
A(1,0) = "B"
A(1,1) = "A"
    Response.Write("A(0,0) = " & A(0,0) & "<br>")
    Response.Write("A(0,1) = " & A(0,1) & "<br>")
    Response.Write("A(1,0) = " & A(1,0) & "<br>")
    Response.Write("A(1,1) = " & A(1,1) & "<br>")

B=A

    Response.Write("B(0,0) = " & B(0,0) & "<br>")
    Response.Write("B(0,1) = " & B(0,1) & "<br>")
    Response.Write("B(1,0) = " & B(1,0) & "<br>")
    Response.Write("B(1,1) = " & B(1,1) & "<br>")
%>
0
 
LVL 11

Expert Comment

by:ASPGuru
ID: 8175476
yes, it does indeed...
i mixed up different languages here...

regards,

ASPGuru
0
 

Author Comment

by:uipavec
ID: 8175837
I would like to thank you all for your effort. However dgorin had provided the most clear and elegant solution to my problem.

I can't believe that I didn't try that myself:-)...among all my tentatives...

FYI: the code I posted was just an example. What I want to do in practice is call a function wich splits a big string that includes data separated with comma delimiter, put the results into a table, sort them and return them as a two dimensional array.

Thanks again,
U.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question