SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: ASP - Multidimentional Array
-
Sep 28, 2010, 00:51 #1
- Join Date
- Sep 2010
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ASP - Multidimentional Array
I'm new to Multidimentional Array's and so I'm obviously not getting something
On my website I want to divide a list of servers into pages - 5 a page. So I thought it would be best to use a multidimentional array. Array(x,y) - xage and y:servers
SplitSearch = split("Server1,Server2,Server3,Server4,Server5,Server6,Server7,Server8,Server9,Server10,Server11,Server12,Server13")
ArrayCounter = 0
ArrayPage = 0
dim PageArray
NumberPerPage = 4
for each x in SplitSearch
If ArrayCounter = NumberPerPage then
ArrayPage = ArrayPage + 1
ArrayCounter = 0
End if
if x <> "" then
ReDim PageArray(ArrayPage,ArrayCounter)
PageArray(ArrayPage,ArrayCounter) = x
' response.write(PageArray(ArrayPage,ArrayCounter)&"<br/>")
ArrayCounter = ArrayCounter + 1
end if
next
response.write(PageArray(1,1)&"<br/>")
Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 1]'
-
Sep 28, 2010, 01:41 #2
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
You could try providing a character (delimiter) on which the string is to be split.
Code:SplitSearch = split("Server1,Server2,Server3,Server4,Server5,Server6,Server7,Server8,Server9 ,Server10,Server11,Server12,Server13", ",")
Split Function
See Also
Join Function
Requirements
Version 2
Returns a zero-based, one-dimensional array containing a specified number of substrings.
Split(expression[, delimiter[, count[, compare]]])
Arguments
expression
Required. String expression containing substrings and delimiters. If expression is a zero-length string, Split returns an empty array, that is, an array with no elements and no data.
delimiter
Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.
count
Optional. Number of substrings to be returned; -1 indicates that all substrings are returned.
compare
Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.
-
Sep 28, 2010, 01:55 #3
- Join Date
- Sep 2010
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Sep 28, 2010, 08:04 #4
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
The problem is that you are redimensioning the array each time, and at the end you have a dimension of (3,1). However you also need a dimension of (2,3) so this will throw an error. Here's some test code that works.
Code ASP:<% Option Explicit Dim SplitSearch,ArrayCounter,ArrayPage,NumberPerPage,x,ArrayMax SplitSearch = split("Server1,Server2,Server3,Server4,Server5,Server6,Server7,Server8,Server9 ,Server10,Server11,Server12,Server13", ",") ArrayCounter = 0 ArrayPage = 0 NumberPerPage = 4 dim PageArray () for each x in SplitSearch if Len (x) > 0 then If ArrayCounter = NumberPerPage then ArrayPage = ArrayPage + 1 ArrayMax = ArrayCounter ArrayCounter = 0 End if ArrayCounter = ArrayCounter + 1 response.write ArrayPage & "," & ArrayCounter & " = " & x & "<br/>" End if next Redim PageArray (ArrayPage, ArrayMax) ArrayCounter = 0 ArrayPage = 0 for each x in SplitSearch if Len (x) > 0 then If ArrayCounter = NumberPerPage then ArrayPage = ArrayPage + 1 ArrayCounter = 0 End if PageArray (ArrayPage, ArrayCounter) = x ArrayCounter = ArrayCounter + 1 end if next response.write(PageArray(1,1)&"<br/>") %>
-
Sep 28, 2010, 08:35 #5
- Join Date
- Apr 2009
- Posts
- 359
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
You might take a look at using the asp dictionary object rather than an array.
http://www.w3schools.com/asp/asp_ref_dictionary.aspDoug G
=====
"If you ain't the lead dog, the view is always the same - Anon
-
Sep 28, 2010, 11:30 #6
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Here's a version that removes the first loop.
Code ASP:<% Option Explicit Dim SplitSearch,ArrayCounter,ArrayPage,NumberPerPage,x,ArrayMax,NumElems SplitSearch = split("Server1,Server2,Server3,Server4,Server5,Server6,Server7,Server8,Server9 ,Server10,Server11,Server12,Server13", ",") NumberPerPage = 4 NumElems = Ubound(SplitSearch) + 1 If Fix (NumElems / NumberPerPage) < 1 Then ArrayPage = 0 ArrayMax = NumElems Mod NumberPerPage Else ArrayPage = Fix (NumElems / NumberPerPage) ArrayMax = NumberPerPage - 1 End If Redim PageArray (ArrayPage,ArrayMax) ArrayCounter = 0 ArrayPage = 0 for each x in SplitSearch if Len (x) > 0 then If ArrayCounter = NumberPerPage then ArrayPage = ArrayPage + 1 ArrayCounter = 0 End if PageArray (ArrayPage, ArrayCounter) = x ArrayCounter = ArrayCounter + 1 end if next Response.Write PageArray(1,1) %>
-
Sep 29, 2010, 00:53 #7
- Join Date
- Sep 2010
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks