By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,164 Members | 850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,164 IT Pros & Developers. It's quick & easy.

Array Help

P: n/a
d4m
I have the following which works okay...

Dim arrayTable As Variant
Dim varTable As Variant

arrayTable = Array("SG", "Oakland", "Server")

For Each varTable In arrayTable

SQL1 = "INSERT INTO tblServers ( Server, Description) " & _
"SELECT TOP 1 Server, Description FROM " & varTable(0) & ";"

Next varTable

But I now need to set the "SELECT TOP 1" to different numbers...so that
SG will select 1, Oakland will select 5, etc. Do I need to create
another array - if so how do I cycle through that - or is there another
way? Thanks for any help.

Jan 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You can use a two-dimensional array to accomplish this task, if I
understand what you're trying to do.

Your array declaration would be changed to this:

Dim arrayTable (2, 1) as String
arrayTable(0, 0)="SG"
arrayTable(0, 1)="1"

arrayTable(1, 0)="Oakland"
arrayTable(1, 1)="5"

arrayTable(2,0)="Server"
arrayTable(2, 1)="3"

Then you can get those values like so:

bob=arrayTable(1,1)

So bob would now be "5".

If I've misunderstood the question, please explain a bit more.

Jan 9 '06 #2

P: n/a
On 9 Jan 2006 12:11:26 -0800, "d4m" <d4****@gmail.com> wrote:

In addition to what Steve said, here are 3 more alternatives:
1: Store this data in a table, and work with a recordset. Now the end
user or administrator can use a form to update this data, and next
time it runs the improved data will be inserted.

2: Use an array of UDT (user-defined type)
Type InsertData
strTableName as string
intTopValues as integer
End Type
dim x(2) as InsertData
x(0).strTable = "SG"
etc.
This makes the array elements self-describing, which is nice.

3: Use an array of arrays:
dim a as variant
a = Array( _
Array("SG", "1"), _
etc.
Then use a(0)(0) etc to get the data.

Choose wisely,

-Tom.
I have the following which works okay...

Dim arrayTable As Variant
Dim varTable As Variant

arrayTable = Array("SG", "Oakland", "Server")

For Each varTable In arrayTable

SQL1 = "INSERT INTO tblServers ( Server, Description) " & _
"SELECT TOP 1 Server, Description FROM " & varTable(0) & ";"

Next varTable

But I now need to set the "SELECT TOP 1" to different numbers...so that
SG will select 1, Oakland will select 5, etc. Do I need to create
another array - if so how do I cycle through that - or is there another
way? Thanks for any help.


Jan 10 '06 #3

P: n/a
>Choose wisely,
....for the fate of your database rests solely in your hands.

Jan 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.