By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

ASP - What happens if an Array has gaps in it?

P: 10
Im trying to create an array by dynamically selecting values from several different fields in a table, but not all the fields will always have data in.

So what I want to know is what would happen in the following situation if several of the fields at random had no values?

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Select Pic1, Pic2, Pic3, Pic4, Pic5, Pic6, Pic7, Pic8, Pic9, Pic10 From Gallery Where GalleryID = 123
  3. %>
  4.  
  5.  
  6. <%
  7. Dim GalleryArray() 'Dynamic array
  8. GalleryArray(0) = "rsGallery.Item("Pic1").value"
  9. GalleryArray(1) = "rsGallery.Item("Pic2").value"
  10. GalleryArray(2) = "rsGallery.Item("Pic3").value"
  11. GalleryArray(3) = ""
  12. GalleryArray(4) = ""
  13. GalleryArray(5) = "rsGallery.Item("Pic6").value"
  14. GalleryArray(6) = "rsGallery.Item("Pic7").value"
  15. GalleryArray(7) = "rsGallery.Item("Pic8").value"
  16. GalleryArray(8) = ""
  17. GalleryArray(9) = "rsGallery.Item("Pic10").value"
  18. For Each item In GalleryArray
  19. %>
  20. <img src="<% Response.Write(item) %><br>
  21. Next
  22. %>
  23.  
In the example above ive left 3 of the aray values blank to simulate blank fields in the database.

What I need to know is would the array:
1) Break
2) skip the blank values and move straight to the next value in the list?
like this:
<img src="Pic1.jpg"><br>
<img src="Pic2.jpg"><br>
<img src="Pic3.jpg"><br>
<img src="Pic6.jpg"><br>
<img src="Pic7.jpg"><br>
<img src="Pic8.jpg"><br>
<img src="Pic10.jpg"><br>

Or would it
3)produce blank outputs to match the blank fields like this:
<img src="Pic1.jpg"><br>
<img src="Pic2.jpg"><br>
<img src="Pic3.jpg"><br>
<img src=""><br>
<img src=""><br>
<img src="Pic6.jpg"><br>
<img src="Pic7.jpg"><br>
<img src="Pic8.jpg"><br>
<img src=""><br>
<img src="Pic10.jpg"><br>



And is there a way of counting the number of actual values in a dynamic array?
Apr 17 '13 #1

✓ answered by DesignsOnline

Ive solved it, in case anyone is having the same problem what fixed it for me was I needed to specify to maximum possible number of records like this:

Dim GalleryArray(39)

Previously I was using this:
Dim GalleryArray()

Share this Question
Share on Google+
9 Replies


P: 10
What im trying to accomplish is number 2 in the possible outcomes above.

Any ideas how I can do this if the way above is wrong?
Apr 17 '13 #2

Rabbit
Expert Mod 10K+
P: 12,369
First, I have to assume that is not the code you're using since there's syntax errors everywhere. And second, your database is unnormalized and you should think about normalizing it so querying it is easier.

It may result in scenario 1 if the values are null and not blank.

It will result in scenario 3 otherwise.

To get scenario 2, you would need to use an If statement to check whether or not the field contains a value before printing it out.
Apr 17 '13 #3

P: 10
Here is the actual code im using, at the moment im getting an error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'ProductID ='.

/NewSite/productdetails.asp, line 512


That line refers to line 21 below: "rsGallery.Open()" line ive done a response.write and I know that the ProductId value is there as it is being written correctly by that response.write, so it seems the error is here somehow:
Expand|Select|Wrap|Line Numbers
  1. WHERE ProductID = " + Replace(rsUpdate__MMColParam, "'", "''") + ""
But here is the code anyway:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim rsGallery__MMColParam
  3. rsGallery__MMColParam = "0"
  4. If (Request.QueryString("ProductID") <> "") Then 
  5.  
  6.   rsGallery__MMColParam = Request.QueryString("ProductID")
  7. response.write rsGallery__MMColParam
  8. End If
  9. %>
  10.  
  11. <%
  12. Dim rsGallery
  13. Dim rsGallery_numRows
  14.  
  15. Set rsGallery = Server.CreateObject("ADODB.Recordset")
  16. rsGallery.ActiveConnection = MM_connTS_STRING
  17. rsGallery.Source = "SELECT BigPict, Pic2, Pic3, Pic4, Pic5, Pic6, Pic7, Pic8, Pic9, Pic10, Pic11, Pic12, Pic13, Pic14, Pic15, Pic16, Pic17, Pic18, Pic19, Pic20, Pic21, Pic22, Pic23, Pic24, Pic25, Pic26, Pic27, Pic28, Pic29, Pic30, Pic31, Pic32, Pic33, Pic34, Pic35, Pic36, Pic37, Pic38, Pic39, Pic40  FROM Products  WHERE ProductID = " + Replace(rsUpdate__MMColParam, "'", "''") + ""
  18. rsGallery.CursorType = 0
  19. rsGallery.CursorLocation = 2
  20. rsGallery.LockType = 1
  21. rsGallery.Open()
  22.  
  23. rsGallery_numRows = 0
  24.  
  25.  
  26. Dim GalleryArray() 
  27. GalleryArray(0) = rsGallery.Fields.Item("BigPict").Value
  28. GalleryArray(1) = rsGallery.Fields.Item("Pic2").Value
  29. GalleryArray(2) = rsGallery.Fields.Item("Pic3").Value
  30. GalleryArray(3) = rsGallery.Fields.Item("Pic4").Value
  31. GalleryArray(4) = rsGallery.Fields.Item("Pic5").Value
  32. GalleryArray(5) = rsGallery.Fields.Item("Pic6").Value
  33. GalleryArray(6) = rsGallery.Fields.Item("Pic7").Value
  34. GalleryArray(7) = rsGallery.Fields.Item("Pic8").Value
  35. GalleryArray(8) = rsGallery.Fields.Item("Pic9").Value
  36. GalleryArray(9) = rsGallery.Fields.Item("Pic10").Value
  37. GalleryArray(10) = rsGallery.Fields.Item("Pic11").value
  38. GalleryArray(11) = rsGallery.Fields.Item("Pic12").value
  39. GalleryArray(12) = rsGallery.Fields.Item("Pic13").value
  40. GalleryArray(13) = rsGallery.Fields.Item("Pic14").value
  41. GalleryArray(14) = rsGallery.Fields.Item("Pic15").value
  42. GalleryArray(15) = rsGallery.Fields.Item("Pic16").value
  43. GalleryArray(16) = rsGallery.Fields.Item("Pic17").value
  44. GalleryArray(17) = rsGallery.Fields.Item("Pic18").value
  45. GalleryArray(18) = rsGallery.Fields.Item("Pic19").value
  46. GalleryArray(19) = rsGallery.Fields.Item("Pic20").value
  47. GalleryArray(20) = rsGallery.Fields.Item("Pic21").value
  48. GalleryArray(21) = rsGallery.Fields.Item("Pic22").value
  49. GalleryArray(22) = rsGallery.Fields.Item("Pic23").value
  50. GalleryArray(23) = rsGallery.Fields.Item("Pic24").value
  51. GalleryArray(24) = rsGallery.Fields.Item("Pic25").value
  52. GalleryArray(25) = rsGallery.Fields.Item("Pic26").value
  53. GalleryArray(26) = rsGallery.Fields.Item("Pic27").value
  54. GalleryArray(27) = rsGallery.Fields.Item("Pic28").value
  55. GalleryArray(28) = rsGallery.Fields.Item("Pic29").value
  56. GalleryArray(29) = rsGallery.Fields.Item("Pic30").value
  57. GalleryArray(30) = rsGallery.Fields.Item("Pic31").value
  58. GalleryArray(31) = rsGallery.Fields.Item("Pic32").value
  59. GalleryArray(32) = rsGallery.Fields.Item("Pic33").value
  60. GalleryArray(33) = rsGallery.Fields.Item("Pic34").value
  61. GalleryArray(34) = rsGallery.Fields.Item("Pic35").value
  62. GalleryArray(35) = rsGallery.Fields.Item("Pic36").value
  63. GalleryArray(36) = rsGallery.Fields.Item("Pic37").value
  64. GalleryArray(37) = rsGallery.Fields.Item("Pic38").value
  65. GalleryArray(38) = rsGallery.Fields.Item("Pic39").value
  66. GalleryArray(39) = rsGallery.Fields.Item("Pic40").value
  67. For Each item In GalleryArray
  68.  
  69. %>
  70.  
  71.  <img src="http://bytes.com/images/<% Response.Write(item) %><br>
  72. <%
  73. Next
  74. %>
  75.  
Apr 17 '13 #4

P: 10
I still need to resolve the error above, but to get arount it for the moment I manually added a valid productid to the SQL query and got the following error:

Microsoft VBScript runtime error '800a0009'

Subscript out of range


The line it is referring to with this error is line 27 from the code in the post above :
Expand|Select|Wrap|Line Numbers
  1. GalleryArray(0) = rsGallery.Fields.Item("BigPict").Value
A google search said that usually means you tried to access an element of an array that was either greater than its ubound or lower than its lbound.

Or it means that the value you are trying load isnt there, but I know that the value from the field "BigPict" is there because I have manually checked the database, and im also loading it on another page...

Im not using ubound or lbound in the code above, do I need to be, and if so, any help on how I would use them with my code above?
Apr 17 '13 #5

Rabbit
Expert Mod 10K+
P: 12,369
If you are absolutely sure that there is a BigPict field in the table, then the next likely cause is that your query returned no rows because of a malformed SQL string.

Please post what your SQL string looks like just before it is sent to the database. We also need to see the table metadata.
Apr 17 '13 #6

P: 10
Hi there, im sorry but I dont understatnd the question.
(Im not a programmer, just a learner)

The code shown in the posts above is the actual exact code from the page. I know that there is a value in the database for BigPict because on a number of other pages I am loading the image that is stored in it.

If it helps the table is in an access database...


I don't have to use this method if there is an easier way to acheive option 2 from my original post?
Apr 17 '13 #7

Rabbit
Expert Mod 10K+
P: 12,369
I don't have to use this method if there is an easier way to acheive option 2 from my original post?
Easier no. Better yes. The better, more correct way is to normalize the database which I mentioned in post #3. It requires more work though.

The code shown in the posts above is the actual exact code from the page.
Code is one thing. What the database gets is another. I need to see what the database is actually getting. I also need to know the table's meta data.

This is code:
Expand|Select|Wrap|Line Numbers
  1. x = "abc"
  2. sql = "select * from table where id = " + x
This is what the database sees:
Expand|Select|Wrap|Line Numbers
  1. select * from table where id = abc
If that is what the database sees, it will result in an error, or it will not return the correct data because the data being passed does not match the metadata.

That is why I can't use just the code alone to diagnose the issue. I need the code, what the database sees, and the metadata. Each is different but related. And I need each to track down the problem. Currently I only have the code. I am missing two pieces of important information for a complete picture.
Apr 17 '13 #8

P: 10
Ive solved it, in case anyone is having the same problem what fixed it for me was I needed to specify to maximum possible number of records like this:

Dim GalleryArray(39)

Previously I was using this:
Dim GalleryArray()
Apr 17 '13 #9

P: 10
Here is the full code in case anyone needs it:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim rsGallery__MMColParam
  3. rsGallery__MMColParam = "0"
  4. If (Request.QueryString("ProductID") <> "") Then 
  5.  
  6.   rsGallery__MMColParam = Request.QueryString("ProductID")
  7.  
  8. End If
  9. %>
  10.  
  11. <%
  12. Dim rsGallery
  13. Dim rsGallery_numRows
  14.  
  15. Set rsGallery = Server.CreateObject("ADODB.Recordset")
  16. rsGallery.ActiveConnection = MM_connTS_STRING
  17. rsGallery.Source = "SELECT BigPict, Pic2, Pic3, Pic4, Pic5, Pic6, Pic7, Pic8, Pic9, Pic10, Pic11, Pic12, Pic13, Pic14, Pic15, Pic16, Pic17, Pic18, Pic19, Pic20, Pic21, Pic22, Pic23, Pic24, Pic25, Pic26, Pic27, Pic28, Pic29, Pic30, Pic31, Pic32, Pic33, Pic34, Pic35, Pic36, Pic37, Pic38, Pic39, Pic40  FROM Products  WHERE ProductID = " & Replace(rsGallery__MMColParam, "'", "''") 
  18. rsGallery.CursorType = 0
  19. rsGallery.CursorLocation = 2
  20. rsGallery.LockType = 1
  21. rsGallery.Open()
  22. %>
  23.  
  24.  
  25.  
  26. <%
  27.  
  28. Dim GalleryArray(39) 
  29. GalleryArray(0) = rsGallery.Fields.Item("BigPict").Value
  30. GalleryArray(1) = rsGallery.Fields.Item("Pic2").Value
  31. GalleryArray(2) = rsGallery.Fields.Item("Pic3").Value
  32. GalleryArray(3) = rsGallery.Fields.Item("Pic4").Value
  33. GalleryArray(4) = rsGallery.Fields.Item("Pic5").Value
  34. GalleryArray(5) = rsGallery.Fields.Item("Pic6").Value
  35. GalleryArray(6) = rsGallery.Fields.Item("Pic7").Value
  36. GalleryArray(7) = rsGallery.Fields.Item("Pic8").Value
  37. GalleryArray(8) = rsGallery.Fields.Item("Pic9").Value
  38. GalleryArray(9) = rsGallery.Fields.Item("Pic10").Value
  39. GalleryArray(10) = rsGallery.Fields.Item("Pic11").value
  40. GalleryArray(11) = rsGallery.Fields.Item("Pic12").value
  41. GalleryArray(12) = rsGallery.Fields.Item("Pic13").value
  42. GalleryArray(13) = rsGallery.Fields.Item("Pic14").value
  43. GalleryArray(14) = rsGallery.Fields.Item("Pic15").value
  44. GalleryArray(15) = rsGallery.Fields.Item("Pic16").value
  45. GalleryArray(16) = rsGallery.Fields.Item("Pic17").value
  46. GalleryArray(17) = rsGallery.Fields.Item("Pic18").value
  47. GalleryArray(18) = rsGallery.Fields.Item("Pic19").value
  48. GalleryArray(19) = rsGallery.Fields.Item("Pic20").value
  49. GalleryArray(20) = rsGallery.Fields.Item("Pic21").value
  50. GalleryArray(21) = rsGallery.Fields.Item("Pic22").value
  51. GalleryArray(22) = rsGallery.Fields.Item("Pic23").value
  52. GalleryArray(23) = rsGallery.Fields.Item("Pic24").value
  53. GalleryArray(24) = rsGallery.Fields.Item("Pic25").value
  54. GalleryArray(25) = rsGallery.Fields.Item("Pic26").value
  55. GalleryArray(26) = rsGallery.Fields.Item("Pic27").value
  56. GalleryArray(27) = rsGallery.Fields.Item("Pic28").value
  57. GalleryArray(28) = rsGallery.Fields.Item("Pic29").value
  58. GalleryArray(29) = rsGallery.Fields.Item("Pic30").value
  59. GalleryArray(30) = rsGallery.Fields.Item("Pic31").value
  60. GalleryArray(31) = rsGallery.Fields.Item("Pic32").value
  61. GalleryArray(32) = rsGallery.Fields.Item("Pic33").value
  62. GalleryArray(33) = rsGallery.Fields.Item("Pic34").value
  63. GalleryArray(34) = rsGallery.Fields.Item("Pic35").value
  64. GalleryArray(35) = rsGallery.Fields.Item("Pic36").value
  65. GalleryArray(36) = rsGallery.Fields.Item("Pic37").value
  66. GalleryArray(37) = rsGallery.Fields.Item("Pic38").value
  67. GalleryArray(38) = rsGallery.Fields.Item("Pic39").value
  68. GalleryArray(39) = rsGallery.Fields.Item("Pic40").value
  69. For Each item In GalleryArray
  70.  
  71.  
  72. %>
  73. <% If item >"" Then %>
  74.  <img src="images/<% Response.Write(item) %>" /><br>
  75.  <%End If%>
  76. <%
  77. Next
  78. %>
Apr 17 '13 #10

Post your reply

Sign in to post your reply or Sign up for a free account.