Solved

asp -- passing an array to a sub

Posted on 2011-09-28
9
274 Views
Last Modified: 2012-05-12
I have a subprocedure:

sub send_email(userid,parts)

Open in new window


The parts argument receives an array.  Here is how I am calling the sub:

send_email(user_id,matchingParts)

Open in new window


matchingParts is an array that i am trying to give to the send_email function.

I do a test and use the Ubound() function to check the upper bound of the array before putting it into the subprocedure and it shows that there are indeed items in the array.  When I check the ubound() value of the array parts in the subprocedure, I get 0 as the upper bound.  So suddenly all the elements in my array are removed just by passing the array.

What is going on and how can i pass the array?
0
Comment
Question by:nickgross19
  • 4
  • 4
9 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36719453
please try calling without the brackets:
send_email user_id,matchingParts
0
 

Author Comment

by:nickgross19
ID: 36719490
tried it, and once the array is passed, the ubound() function returns 0.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36719498
can you please show the full code of that function?
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:nickgross19
ID: 36719521
sub send_email(userid,parts)
	dim htmlParts
	dim xyz
	response.Write("passed ubound: "&ubound(parts)&"<br>")

Open in new window


As you can see, right away i get a 0 returned by the ubound() function.  The only thing that happens before this is two dim statemtns
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36719568
sounds ok, can you please show the relevant code that builds the array, and calls send_mail function?
0
 

Author Comment

by:nickgross19
ID: 36719619
This is the code that builds the array:
do while not ngrs2.eof
		if part_ic = "" then
			part_ic = 0
		end if
		ReDim Preserve mathcingParts(part_ic)
		mathcingParts(part_ic) = ngrs2.Fields("ID")
		part_ic = part_ic + 1
		ngrs2.MoveNext
	loop

Open in new window

0
 

Author Comment

by:nickgross19
ID: 36719658
I got it to work somehow, i don't know what i was doing wrong...  

Thanks for your help.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 36813058
I found the issue..

you wrote:
send_email(user_id,matchingParts)

but in the code you build:
mathcingParts

hc vs ch

just a typo
0
 
LVL 28

Expert Comment

by:sybe
ID: 36814007
An array with Ubound = 0 has one element. Arrays start counting at 0. If you have an empty array, it will return -1 on Ubound.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question