473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Mutli dimensional Array in ASP

Hi Everyone,

I have a store procedure returning 7 rows for 3 columns, basically I am retrieving:
Descriptor Lower Range Upper Range
D1 1 10
D2 2 11
D3 3 12
D4 4 13
D5 5 14
D6 6 15
D7 7 16

Now on my ASP page there are Text values that can be entered for Descriptors D1 - D7 and I need to validate the form to ensure that all values for each descriptor mentioned are within the lower and upper range for that descriptor in the look up table.

For example: If I have a user entering value of D4 from the form, than I have to find out if it is between 4-13, if not send them a pop up to say, please enter within that range.

Solution I thought:
Get the record set into array in the ASP page and than for each descriptor validate the form value entered is within the range.

Problem: Is that I can not get my ASP page to return value more than [3,2] :(

My Code in the ASP page is:

[ASP]
<%

Dim ValConn, ValCmd, ValRS, ValParam, ValArray, Region, temp
Dim intLastCol, intLastRow, intRow, intCol
temp = "T"


SET ValConn = Server.CreateObject("ADODB.Connection")
SET ValCmd = Server.CreateObject("ADODB.Command")
SET ValRS = Server.CreateObject("ADODB.Recordset")
Set ValParam=Server.CreateObject("ADODB.Parameter")
ValConn.Open Application("Connection")

SET ValCmd.ActiveConnection = ValConn


ValCmd.CommandType = 4
ValCmd.CommandText = "sp_Validate_Range_Values"
Set ValParam = ValCmd.CreateParameter("Region", 200,1,1,temp)
ValCmd.Parameters.Append ValParam

SET ValRS = ValCmd.Execute

ValArray = ValRS.GetRows

ValRS.Close
SET ValRS= Nothing



'intLastCol = UBound(ValArray, 1)
'intLastRow = Ubound(ValArray, 2)


'For intRow = 0 to intLastCol
'For intCol = 0 to intLastRow
'Response.Write ValArray(intCol, intRow) & " "
'Next
'Response.Write "<Br>"
'Next

Response.Write ValArray (0,0,)
Response.Write "<Br>"

Response.Write ValArray (0,1)
Response.Write "<Br>"

Response.Write ValArray (0,2)
Response.Write "<Br>"

Response.Write ValArray (1,0)
Response.Write "<Br>"

Response.Write ValArray (1,1)
Response.Write "<Br>"

Response.Write ValArray (1,2)
Response.Write "<Br>"

Response.Write ValArray (2,0)
Response.Write "<Br>"

Response.Write ValArray (2,1)
Response.Write "<Br>"

Response.Write ValArray (2,2)
Response.Write "<Br>"

Response.Write ValArray (3,0)
Response.Write "<Br>"

Response.Write ValArray (3,1)
Response.Write "<Br>"

Response.Write ValArray (3,2)
Response.Write "<Br>"

Response.Write ValArray (4,0)
Response.Write "<Br>"

Response.Write ValArray (4,1)
Response.Write "<Br>"

Response.Write ValArray (4,2)
Response.Write "<Br>"

Response.Write ValArray (5,0)
Response.Write "<Br>"

Response.Write ValArray (5,1)
Response.Write "<Br>"

Response.Write ValArray (5,2)
Response.Write "<Br>"



ValConn.Close
SET ValConn = Nothing


Response.Write("Hello")

%>
[/ASP]

ERROR MESSAGE ON ASP PAGE IS:

D1
D2
D3
1
2
3
10
11
13

Microsoft VBScript runtime error '800a0009'

Subscript out of range: '[number: 3]'

/scidc/test.asp, line 74

I believe the issue is because ASP is making an 2D array whereas I need a 3D array and I tired finding how to get multi dimensional array in ASP but none of them were useful, would be glad if someone can explain what is wrong and what can be a possible solution to make the code work.

Thanks in advance,
Sree
Dec 7 '07 #1
3 1431
Nicodemas
164 Expert 100+
It seems you could skip the need for a big array if your SQL query does the testing for you. I have written a sample piece of psuedocode.

Expand|Select|Wrap|Line Numbers
  1. TABLE: Limits
  2.  
  3. Descriptor | Lower_Range | Upper_Range
  4. D1              1            10
  5. D2              2            11
  6. D3              3            12
  7. D4              4            13
  8. D5              5            14
  9. D6              6            15
  10. D7              7            16
  11.  
SQL:

Expand|Select|Wrap|Line Numbers
  1. "SELECT descriptor FROM Limits WHERE Lower_Range >= "& userInput_Lower &" AND Upper_Range <= "& userInput_Uppert &" AND descriptor = '"& userInput_Descriptor &"'"
VBScript Logic:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. '// your code which executes the query...
  3. '// returns recordset ("rs")
  4.  
  5. if rs.eof then
  6.    system_message = "you must enter a value with the valid range for the "& userInput_Descriptor &" field."
  7.    '// do some error processing...
  8. else
  9.    '// do regular processing
  10. end if
  11. %>
  12.  
Dec 7 '07 #2
Nicodemas
164 Expert 100+
You could do it your way, though.

Expand|Select|Wrap|Line Numbers
  1. TABLE: Limits
  2.  
  3. Descriptor | Lower_Range | Upper_Range
  4. D1              1            10
  5. D2              2            11
  6. D3              3            12
  7. D4              4            13
  8. D5              5            14
  9. D6              6            15
  10. D7              7            16
  11.  
SQL:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Limits
VBScript Logic:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. ' your code executes the query, and
  3. ' returns recordset "rs"
  4.  
  5.  
  6. aResults = rs.getRows
  7. set rs = nothing
  8.  
  9.  
  10. ' 2d array will look like this:
  11. '============================================
  12. 'row | descriptor (0) | lower (1) | upper (2)
  13. '============================================
  14. ' 0      D1                1           10
  15. ' 1      D2                2           11
  16. ' 2      D3                3           12
  17. ' et cetera, just like your database table
  18.  
  19.  
  20. ' To ask, "Did the user enter a valid lower range value for D2?", you would say
  21. '
  22. ' if userInput_Lower >= aResults(1, 1) then
  23. '    ... yes, is valid, do stuff
  24. ' else
  25. '    ... no, is invalid, do stuff
  26. ' end if
  27.  
  28. ' Remember: get rows will create enough dimensions to accommodate 
  29. ' the result set. The first number of the array represents the "column", 
  30. ' the second number, the "row."
  31. %>
  32.  
Dec 7 '07 #3
You could do it your way, though.

Expand|Select|Wrap|Line Numbers
  1. TABLE: Limits
  2.  
  3. Descriptor | Lower_Range | Upper_Range
  4. D1              1            10
  5. D2              2            11
  6. D3              3            12
  7. D4              4            13
  8. D5              5            14
  9. D6              6            15
  10. D7              7            16
  11.  
SQL:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Limits
VBScript Logic:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. ' your code executes the query, and
  3. ' returns recordset "rs"
  4.  
  5.  
  6. aResults = rs.getRows
  7. set rs = nothing
  8.  
  9.  
  10. ' 2d array will look like this:
  11. '============================================
  12. 'row | descriptor (0) | lower (1) | upper (2)
  13. '============================================
  14. ' 0      D1                1           10
  15. ' 1      D2                2           11
  16. ' 2      D3                3           12
  17. ' et cetera, just like your database table
  18.  
  19.  
  20. ' To ask, "Did the user enter a valid lower range value for D2?", you would say
  21. '
  22. ' if userInput_Lower >= aResults(1, 1) then
  23. '    ... yes, is valid, do stuff
  24. ' else
  25. '    ... no, is invalid, do stuff
  26. ' end if
  27.  
  28. ' Remember: get rows will create enough dimensions to accommodate 
  29. ' the result set. The first number of the array represents the "column", 
  30. ' the second number, the "row."
  31. %>
  32.  
Thanks a lot for you help. Much appreciate.

Sree
Dec 11 '07 #4

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

Similar topics

2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
6
by: Ruben | last post by:
I'm trying to pass an array of string to a function without knowing how many strings I have beforehand. I've defined one functions as char * insert(char table,int cols, char values); out of...
16
by: rguti | last post by:
Hi, How do I create a two dimensional array? I have created a one dimensional doing this: Dim laFields As ArrayList = New ArrayList How about to do a 2 dimensional?
60
by: Peter Olcott | last post by:
I need to know how to get the solution mentioned below to work. The solution is from gbayles Jan 29 2001, 12:50 pm, link is provided below: >...
22
by: spam.noam | last post by:
Hello, I discovered that I needed a small change to the Python grammar. I would like to hear what you think about it. In two lines: Currently, the expression "x" is a syntax error. I suggest...
6
by: fniles | last post by:
I need to store information in a 2 dimensional array. I understand ArrayList only works for a single dimensional array, is that correct ? So, I use the 2 dimensional array like in VB6. I pass the...
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
5
by: nelly0 | last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.