PC Review


Reply
Thread Tools Rate Thread

array question, referenceing

 
 
Al
Guest
Posts: n/a
 
      12th Jul 2007
Hey all

I have 2 arrays called arr1 and arr2 (string arrays)

arr1 contains the values 1, 2, 3
arr2 contains the values a, b, c

I have a third array, namesarr (also String), which contains the names
of the first 2 arrays

I am trying to have the following output on my excell sheet

arr1
1
2
3
arr2
a
b
c

Here is the code I am using:

For S = 0 To UBound(namesarr)
ActiveCell.Value = namesarr(S)

For Each element In Array(namesarr(S))
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = element
Next element
Next S

here is what I get:

arr1
arr2

The contents of each of my arrays don't get printed. I am sure that I
am referencing them incorrectly, but I can't figure it out. any help
appreciated. Thanks

Al

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      12th Jul 2007
try this

myoffset = 1
For S = 0 To UBound(namesarr)
ActiveCell.Value.offset(myoffset,0) = namesarr(S)
myoffset = myoffset + 1

For Each element In Array(namesarr(S))
ActiveCell.Value.offset(myoffset,0) = element
myoffset = myoffset + 1
Next element
Next S


"Al" wrote:

> Hey all
>
> I have 2 arrays called arr1 and arr2 (string arrays)
>
> arr1 contains the values 1, 2, 3
> arr2 contains the values a, b, c
>
> I have a third array, namesarr (also String), which contains the names
> of the first 2 arrays
>
> I am trying to have the following output on my excell sheet
>
> arr1
> 1
> 2
> 3
> arr2
> a
> b
> c
>
> Here is the code I am using:
>
> For S = 0 To UBound(namesarr)
> ActiveCell.Value = namesarr(S)
>
> For Each element In Array(namesarr(S))
> ActiveCell.Offset(1, 0).Select
> ActiveCell.Value = element
> Next element
> Next S
>
> here is what I get:
>
> arr1
> arr2
>
> The contents of each of my arrays don't get printed. I am sure that I
> am referencing them incorrectly, but I can't figure it out. any help
> appreciated. Thanks
>
> Al
>
>

 
Reply With Quote
 
Al
Guest
Posts: n/a
 
      12th Jul 2007
Thanks for the help, but your code prodiced no output at all... any
other ideas?

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      12th Jul 2007

myoffset = 1
Try removing value. It really belongs at the end.

For S = 0 To UBound(namesarr)
ActiveCell.offset(myoffset,0) = namesarr(S)
myoffset = myoffset + 1

For Each element In Array(namesarr(S))
ActiveCell.offset(myoffset,0) = element
myoffset = myoffset + 1
Next element
Next S

"Al" wrote:

> Thanks for the help, but your code prodiced no output at all... any
> other ideas?
>
>

 
Reply With Quote
 
Al
Guest
Posts: n/a
 
      13th Jul 2007
Still nothing...

I am quite certain that the line:

For Each element In Array(namesarr(S))

is incorrect. when I do debug and hold my mouse over
"Array(namesarr(S))" I get a tooltip that says namesarr(S)="arr1"

the arr1 in this case (I surmise) is a word, or a variable, NOT the
array called arr1.

How do I properly refer to the array arr1?

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      13th Jul 2007
Remove parethesis

For Each element In Array(namesarr)

"Al" wrote:

> Still nothing...
>
> I am quite certain that the line:
>
> For Each element In Array(namesarr(S))
>
> is incorrect. when I do debug and hold my mouse over
> "Array(namesarr(S))" I get a tooltip that says namesarr(S)="arr1"
>
> the arr1 in this case (I surmise) is a word, or a variable, NOT the
> array called arr1.
>
> How do I properly refer to the array arr1?
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Jul 2007
Are you looking for something like:

arr1 1
2
arr2 a
b
c

The array names in one column and the elements in the column to the right.

If yes:

Option Explicit
Sub testme01()

Dim arr1 As Variant
Dim arr2 As Variant
Dim NamesArr As Variant
Dim RealArr As Variant
Dim iCtr As Long
Dim jCtr As Long
Dim DestCell As Range

arr1 = Array(1, 2, 3)
arr2 = Array("a", "b", "c")

'make sure both of these have the same number of elements!
NamesArr = Array("arr1", "arr2")
RealArr = Array(arr1, arr2)

Set DestCell = ActiveCell
For iCtr = LBound(NamesArr) To UBound(NamesArr)
DestCell.Value = NamesArr(iCtr)
'move over for the first element of the array
Set DestCell = DestCell.Offset(0, 1)
For jCtr = LBound(RealArr(iCtr)) To UBound(RealArr(iCtr))
DestCell.Value = RealArr(iCtr)(jCtr)
'get ready for the next element
Set DestCell = DestCell.Offset(1, 0)
Next jCtr
'come back to original column for next array
Set DestCell = DestCell.Offset(-1, -1)
Next iCtr
End Sub

I'm not sure if NamesArr contained the names of the arrays or the actual
arrays. But in any case, I don't think you're going to use the string as a
variable.

If you did:
Dim NamesArr as Variant
NamesArr = array("arr1","arr2")

Then when you're in the loop, this line:

For Each element In Array(namesarr(S))
is essentially this:
For each element in array("arr1")
and then
For each element in array("arr2")

In either case, you're looping through an array with just one element -- "arr1"
the first time and "arr2" the second time.



Al wrote:
>
> Hey all
>
> I have 2 arrays called arr1 and arr2 (string arrays)
>
> arr1 contains the values 1, 2, 3
> arr2 contains the values a, b, c
>
> I have a third array, namesarr (also String), which contains the names
> of the first 2 arrays
>
> I am trying to have the following output on my excell sheet
>
> arr1
> 1
> 2
> 3
> arr2
> a
> b
> c
>
> Here is the code I am using:
>
> For S = 0 To UBound(namesarr)
> ActiveCell.Value = namesarr(S)
>
> For Each element In Array(namesarr(S))
> ActiveCell.Offset(1, 0).Select
> ActiveCell.Value = element
> Next element
> Next S
>
> here is what I get:
>
> arr1
> arr2
>
> The contents of each of my arrays don't get printed. I am sure that I
> am referencing them incorrectly, but I can't figure it out. any help
> appreciated. Thanks
>
> Al


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referenceing Projects =?Utf-8?B?Sm9l?= Microsoft ASP .NET 7 9th Nov 2005 07:23 PM
Referenceing subforms Scott Microsoft Access Queries 1 21st Jun 2004 08:46 PM
referenceing a class in a another .cs file Larry Hilley Microsoft C# .NET 2 14th Feb 2004 09:07 AM
referenceing in vb .net =?Utf-8?B?YmFmaWRp?= Microsoft VB .NET 1 28th Jan 2004 03:56 PM
Help with cell referenceing Dab Microsoft Excel Discussion 2 26th Aug 2003 05:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:37 PM.