Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ArrayList, "shopping basket" 1

Status
Not open for further replies.

englundn

Programmer
Jun 1, 2007
23
FI
I have a slight problem with arraylist in Access VB. I want to select different report ID's into a basket. From the basket i want to just show the selected reports and then print or copy them to my hard disk.

The problem comes when i try to create an array or use the arraylist. I don't exactly know what references to include in VB or actually i can't find the System.Collection reference in VB.

My code so far:
Public Basket As New ArrayList

Action code:
Basket.Add (toBasket) 'integer value

The error i get is that the there is an a user-defined value hasn't been defined. This points to "Public Basket As New ArrayList"
 
i can't find the System.Collection reference in VB
Sounds like you are talking about VB.NET. VBA (Visual Basic for Applications) has nothing to do with .NET.

Hence there is no ArrayList.

The closest equivalent to an ArrayList might be a Collection object, or the Dictionary object as Remou has pointed out.

 
englundn,
[tt]ArrayList[/tt] is .net. If you really want to use it in VBA you can add a reference to mscorlib (mscorlib.tlb) but you will want to be very sure your users have this library (framework 1.1 or newer) available on their machines.

CMP


[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Thank you for your replies, but they didn't actually work the way i wanted.
The Dictionary object with the "set fd=" functions only within the same procedure as it's called.
I would need somekind of global variable where i can choose several ID's to a "basket"/array and then make a filter of those array values.

Picture of my intentions.
 
I would need somekind of global variable where i can choose several ID's to a "basket"/array and then make a filter of those array values.

This is a database, so I suggest a table.
 
Is it possible to create temporary tables in Access? My DB will have several users so a table with static name is not possible.
 
Not in the sense of an SQL Server temporary table. However, there is no reason why you should not include the user name in the table:

environ("username"

or


Or, if you must, you could use the front-end to store this data.
 
Ok. That was what i thought also. Still trying to experiment with arrays and making it "easier" without the table creating procedure even if it would make the work easier.

Thank you.
 
I should have mentioned that you can use a global variable.

Code:
Option Explicit

Global d   ' Create a variable.

Sub CreateD()

Set d = CreateObject("Scripting.Dictionary")

d.Add "a", "Athens"   ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"

End Sub

However, global variables are not usually a good idea:

In a Visual Basic application, global variables should be used only when there is no other convenient way to share data between forms. When global variables must be used, it is good practice to declare them all in a single module, grouped by function. Give the module a meaningful name that indicates its purpose, such as Public.bas.

-- Visual Basic Concepts: Constant and Variable Naming Conventions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top