Solved

Loading a bi-dimensional array and RS(s)

Posted on 2001-08-06
9
275 Views
Last Modified: 2008-03-06
Dear all,

I have an array containing a list of product IDs related to a certain user.

Dim counter As Integer
counter = 0
For counter = LBound(arryID) To UBound(arryID)
MsgBox arryID(counter)
Next counter

arryID is the array containing the IDs.

What I would need is the following:
within the loop of the array -- x each element of the array -- I need to launch n SELECT(s)of this kind: select from mytable where ProductID = ID.
Then I need to load a bi-dimensional array where the 1 dimension is (one of) the ID on the basis of which I am doing the SELECT , and the 2 dimension is a string of all the exixting values in the DB for that ID chained by a comma.

Thanx.
 

0
Comment
Question by:skullj
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
Could you show an example of the exact formatting?
0
 

Author Comment

by:skullj
Comment Utility
Thanx CJ_S

'1 VERSION OF THE STRING

 stringa = stringa + Rs2.Fields("ID").VALUE + ","

 '2 VERSION OF THE STRING: I need to strip off the last ","
 'I need this formatted version to be loaded into the array

 stringa = mid(stringa ,1,len(stringa )-1)  
0
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
Doesn't make much sense to me so far.

if I understand you correctly you are trying to achieve the following:
- loop through the array
- inside the loop you create an sql statement which will select some data out of the database
- then you want to retrieve the id, and place it in the first entry, the second entry will be used to place all other fields, comma sperated. is that correct? if so, the following might help you a bit

Declare the following type:
Public Type MyRS
   id as integer
   addData as string
End Type


then in your normal function / loop

Dim counter As Integer
Dim myArray() as MyRS
For counter = LBound(arryID) To UBound(arryID)
   .. create sql statement...that's up to you..
   rs.open SQLSTATEMENT
   ReDim preserve myArray(counter)
   myArray(counter).id = rs("id")
   for each y in rs.fields
      tmpStr = tmpStr & rs(y).Value & ","
   next
   tmpStr = Left(tmpStr, len(tmpStr-1))
   myArray(counter).addData = tmpStr
Next counter

If this is not what you wer elooking for, just clarify some more on your goal.

regards,
CJ
0
 

Author Comment

by:skullj
Comment Utility
Dear CJ_S,
I need then to call the bi-dimensional array that will be returned form the VB function from ASP...
thanx
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
>> be returned form the VB function from ASP

??
0
 

Author Comment

by:skullj
Comment Utility
TO ASP ..SORRY
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 200 total points
Comment Utility
UHM...

public function myfunction() as variant()
Dim counter As Integer
Dim myArray as variant

For counter = LBound(arryID) To UBound(arryID)
  .. create sql statement...that's up to you..
  rs.open SQLSTATEMENT
  ReDim preserve myArray(counter)
  for each y in rs.fields
     tmpStr = tmpStr & rs(y).Value & ","
  next
  tmpStr = Left(tmpStr, len(tmpStr-1))
  myArray(counter) = Array(rs("id"), tmpStr)
Next counter

myfunction = myArray
end function

I suppose that would return the array to the asp page. Now you should be able to use the following in your asp page:
Set x = Server.CreateObject("Myproject.classname")
y = x.myfunction
for i=lbound(y) to ubound(y)
   response.write("id: " & i(0) & "<br>data: " & i(1))
next

rgards,
CJ
0
 

Author Comment

by:skullj
Comment Utility
TO ASP ..SORRY
0
 

Author Comment

by:skullj
Comment Utility
sorry..just a last question : what is Array(rs("id"), tmpStr)??
Thank
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now