Advertisement

06.12.2008 at 10:15AM PDT, ID: 23480327
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

Ubound in Multi-dimensional array

Asked by Gerano in Scripting Languages, MS SQL Server

Tags:

I'm creating a dynamic favourites list using arrays.

So far all I wanted to do was to make sure I can create the array, add and item, check the size with ubound and remove an item,  writing this to the page as I go to make sure it works.

It all works fine in a normal array but once I've created a multi dimensional array the ubound no longer works and anything I do based on the ubound value fails after that.

Bear in mind that I wrote the syntax by making it up as I went along using code bits I've found and articles I read and what knowledge I have of VB Script. So it's not necessarily optimal. That being disclaimed here is the code:

<% Dim myArray() 'Create the dyamic array
 ReDim myArray(1,4) 'give it a size with redim

 'fill the array with items
myArray(0,0) = "Skye"
myArray(1,0) = "12 months"
myArray(0,1) = "Sto"
myArray(1,1) = "40 years"
myArray(0,2) = "Ilana"
myArray(1,2) = "38 years"
myArray(0,3) = "Jamie"
myArray(1,3) = "13 years"
myArray(0,4) = "Ribi"
myArray(1,4) = "3 years"
%>

<strong>The first array, written to the page</strong><br>

<% 'write the array items to the page
  For i = 0 to 4
 response.write(myArray(0,i))&"&nbsp;"&(myArray(1,i)& "<br>")
 Next   %>
 
 <br> <% 'find the size of the array and write that to the page %>
 <strong>The size of the first array is <%  = UBound(myArray)   -UBound(myArray)   - LBound(myArray) %></strong><br><br>
 

<% Dim maxNum, newMaxNum 'create a current size variable and set it equal the array size and create a new max size variable
maxNum =  UBound(myArray) - LBound(myArray)
newMaxNum = MaxNum + 1 'grow it by one place using the current size + 1%>
<% ReDim Preserve myArray(1,newMaxNum)  'redim and preserve the array %>
 
<% myArray(0,newMaxNum) = "Heanly"
myArray(1,newMaxNum) = "3 years"'Give the new item a name%>
 
<% 'write the new array to the page
  For i = 0 to newMaxNum
 response.write(myArray(0,i))&"&nbsp;"&(myArray(1,i) & "<br>")
 Next   %>
 
 <br><strong>The size of the new array is <%  = UBound(myArray) - LBound(myArray)  %> </strong><br><br>


<strong> Remove an item from the Array</strong><br>

<%  
      
removedItem = False
    Dim itemToRemove
    itemToRemove = "Sto"
    arrayLength = UBound(myArray)

    for i = 0 to arrayLength
        if (myArray(1,i) = itemToRemove) then
            ' If we found our search term in array
            ' we are copying array to a new array list
            myArray(i) = myArray(arrayLength)
            ' So now our first value must be TRUE
            removedItem = True
        end if
    next

    if (removedItem = True) then
        ' Let's make a new array and pass all values
        redim preserve myArray(arrayLength - 1)
    end if    %>
      
      <% newMaxNo = UBound(myArray) - LBound(myArray)  %>
      
      <% 'write the array sans removed item to page %>
      <br>
        <% For i = 0 to newMaxNo %>
 <% response.write(myArray(0,i))&"&nbsp;"&(myArray(1,i)) %><br>
 <% Next %>
 
 <br><br>
 <strong>Add yet another item to the array</strong><br><br>
 
 <%maxNum =  UBound(myArray) - LBound(myArray)
newMaxNum = MaxNum + 1 'grow it by one place using the current size + 1%>
<% ReDim Preserve myArray(1,newMaxNum)  'redim and preserve the array %>
 
<% myArray(0,newMaxNum) = "Moss"
myArray(1,newMaxNum) = "10 years"'Give the new item a name%>
 
<% 'write the new array to the page
  For i = 0 to newMaxNum
 response.write(myArray(0,i))&"&nbsp;"&(myArray(1,i) & "<br>")
 Next   %>

Start Free Trial
 
Loading Advertisement...
 
[+][-]06.12.2008 at 11:24AM PDT, ID: 21772278

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.12.2008 at 01:11PM PDT, ID: 21773255

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.13.2008 at 12:22AM PDT, ID: 21776590

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 05:17AM PDT, ID: 21792802

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 08:28AM PDT, ID: 21794554

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 11:51AM PDT, ID: 21796305

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Scripting Languages, MS SQL Server
Tags: ASP VBScript
Sign Up Now!
Solution Provided By: gregcmcse
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628