ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 8th, 2004, 08:58 AM
jimriggott jimriggott is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 53 jimriggott User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 13 m 57 sec
Reputation Power: 6
help with Array

I have a script which is used to randomly allocate a teaching slot to a teacher.

What it does it to initially select which teachers are free for a time slot

Then it counts how many are free for the time slot.

Then it uses the randomize routine below to randomly allocate the lesson to a teacher.

Since arrays start to count at zero, then I have to use the line below to reduce the count by 1

e.g. if the sql shows 'FREE_TCHR_CT' is 2, I have to reduce that to 1, so that the array can count from 0 to 1, instead of from 0 to 2, which will end up throwing out a fld_t value of nothing...

Anyway, most of the time this process works, but I occasionally get this error:

Microsoft VBScript runtime (0x800A0009)
Subscript out of range: 'lrandom'
/japan/users/save.asp, line 59

line 59 is:

t_id = myArray(lrandom)

I think this may only occur when FREE_TCHR_CT = 2

Can anyone suggest why this might be happening please?

Thanks

Jim

code below:

--------------------
sql002 = "SELECT fld_id, fld_t, (time_to_sec(fld_time)/1800) as periodnumber FROM appointments "
sql002 = sql002 & "where fld_date = '"&d&"' AND (time_to_sec(fld_time)/1800) = '"&t&"' AND fld_cat = 2 GROUP BY fld_id"

response.write "sql002<BR>" & sql002 & "<HR>"

set rs002 = oConn.Execute(sql002)

'since there are free teacher(s) count the number of free teachers

sql003 = "SELECT COUNT(fld_id) AS FREE_TCHR_CT FROM appointments where fld_date = '"&d&"' AND (time_to_sec(fld_time)/1800) = '"&t&"' AND fld_cat = 2 "
response.write sql003 & "<HR>"
set rs003 = oConn.Execute(sql003)
FREE_TCHR_CT = rs003("FREE_TCHR_CT")
response.write "FREE_TCHR_CT: " & FREE_TCHR_CT & "<BR>"

'if there is more than one teacher free then do the random thing

if FREE_TCHR_CT > 1 then

FREE_TCHR_CT = FREE_TCHR_CT-1
response.write "FREE_TCHR_CT rand: " & FREE_TCHR_CT & "<BR>"
rs003.Close:set rs003=nothing

'response.write "<br><br>FREE_TCHR_CT: " & FREE_TCHR_CT & "<hR>"

dim myArray
ReDim myArray(FREE_TCHR_CT)

randomize

x = 0
do while not rs002.eof
y = rs002("fld_id")

myArray(x) = rs002("fld_t")

x=x+1
rs002.MoveNext
Loop
rs002.close:set rs002 = nothing

upperbound=ubound(myArray)
lowerbound=0
lrandom = ((upperbound - lowerbound + 1) * rnd + lowerbound)

t_id = myArray(lrandom)

else

t_id = rs002("fld_t")

end if

response.write "<hr>t_id: " & t_id & "<HR>"
'response.write "row_id: " & row_id & "<HR>"

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > help with Array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT