Solved

Loading a bi-dimensional array and RS(s)

Posted on 2001-08-06
9
293 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
ID: 6355047
Could you show an example of the exact formatting?
0
 

Author Comment

by:skullj
ID: 6355079
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
ID: 6355113
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:skullj
ID: 6355117
Dear CJ_S,
I need then to call the bi-dimensional array that will be returned form the VB function from ASP...
thanx
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6355124
>> be returned form the VB function from ASP

??
0
 

Author Comment

by:skullj
ID: 6355132
TO ASP ..SORRY
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 200 total points
ID: 6355158
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
ID: 6355225
TO ASP ..SORRY
0
 

Author Comment

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

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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