PC Review


Reply
Thread Tools Rate Thread

Assigning big 2D arrays

 
 
=?Utf-8?B?U8O2cmVuX01hcm9kw7ZyZW4=?=
Guest
Posts: n/a
 
      26th Jan 2007
Hi,

Assigning small 2D arrays is easy.
This is a 3x6 array:
Array_A = [{1, 3, 6, 10, 0, 0; 1, 1.2, 4.5, 6.8, 9.2, 10; 0, 0, 0, 0, 2, 3}]
Every line is separated by ";".

But when I type in bigger arrays and cut the line with a " _", as I do for
all other lines in the code that becomes to long, I get an error message,
"Missing end bracket"
Can anyone tell me why this doesn't work?

How can I assign a 4x49 (or even 4x97) element array?

I can assign 1D arrays with 49 elements, but is it possible to build a 2D
array out of these 1D arrays? Is that a way to get round the probelm?

I have also problem with dimensioning these arrays.
When I write
Dim Array_A(1 To 4, 1 To 49) As Variant
I get an error "Can't assign to an array" when I Assign to the array
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      26th Jan 2007
sval = "6,1,5,6;5,1,5,25;4,1,5,43;7,1,6,10;5,3,6,38;" & _
"5,1,7,12;3,1,7,32;5,1,7,50;4,5,9,18;2,1,18,31;3,1,21" & _
",28;5,1,23,12"
varr = Evaluate("{" & sval & "}")

is a way to use continuations, but I think this method runs out of steam
very quickly, it won't handle a 4x49 array.

For that I think you would be best to load a worksheet range, and load from
there.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Sören_Marodören" <(E-Mail Removed)> wrote in message
news:60CE796C-0E94-4821-8EBD-(E-Mail Removed)...
> Hi,
>
> Assigning small 2D arrays is easy.
> This is a 3x6 array:
> Array_A = [{1, 3, 6, 10, 0, 0; 1, 1.2, 4.5, 6.8, 9.2, 10; 0, 0, 0, 0, 2,
> 3}]
> Every line is separated by ";".
>
> But when I type in bigger arrays and cut the line with a " _", as I do for
> all other lines in the code that becomes to long, I get an error message,
> "Missing end bracket"
> Can anyone tell me why this doesn't work?
>
> How can I assign a 4x49 (or even 4x97) element array?
>
> I can assign 1D arrays with 49 elements, but is it possible to build a 2D
> array out of these 1D arrays? Is that a way to get round the probelm?
>
> I have also problem with dimensioning these arrays.
> When I write
> Dim Array_A(1 To 4, 1 To 49) As Variant
> I get an error "Can't assign to an array" when I Assign to the array



 
Reply With Quote
 
Leo Heuser
Guest
Posts: n/a
 
      26th Jan 2007
"Sören_Marodören" <(E-Mail Removed)> skrev i en
meddelelse news:60CE796C-0E94-4821-8EBD-(E-Mail Removed)...
> Hi,
>
> Assigning small 2D arrays is easy.
> This is a 3x6 array:
> Array_A = [{1, 3, 6, 10, 0, 0; 1, 1.2, 4.5, 6.8, 9.2, 10; 0, 0, 0, 0, 2,
> 3}]
> Every line is separated by ";".
>
> But when I type in bigger arrays and cut the line with a " _", as I do for
> all other lines in the code that becomes to long, I get an error message,
> "Missing end bracket"
> Can anyone tell me why this doesn't work?
>
> How can I assign a 4x49 (or even 4x97) element array?
>
> I can assign 1D arrays with 49 elements, but is it possible to build a 2D
> array out of these 1D arrays? Is that a way to get round the probelm?
>
> I have also problem with dimensioning these arrays.
> When I write
> Dim Array_A(1 To 4, 1 To 49) As Variant
> I get an error "Can't assign to an array" when I Assign to the array



Hi Sören

You can use this approach instead, but there is a limit to the number
of linebreaks in a line (which I can't remember, 24???):

Array_A = Evaluate("{1, 3, 6, 10," & _
"0, 0; 1, 1.2, 4.5, 6.8, 9.2, 10;" & _
"0, 0, 0, 0, 2, 3}")

or something along these lines:

Option Base 1
Sub test()
Dim Array_A(1 To 3) As Variant
Dim Counter As Long
Dim Counter1 As Long
Dim NewArray(1 To 3, 1 To 6) As Variant

Array_A(1) = Array(1, 3, 6, 10, 0, 0)
Array_A(2) = Array(1, 1.2, 4.5, 6.8, 9.2, 10)
Array_A(3) = Array(0, 0, 0, 0, 2, 3)

For Counter = 1 To 3
For Counter1 = 1 To 6
NewArray(Counter, Counter1) = Array_A(Counter)(Counter1)
Next Counter1
Next Counter

End Sub



--
Best regards
Leo Heuser

Followup to newsgroup only please.




 
Reply With Quote
 
=?Utf-8?B?U8O2cmVuX01hcm9kw7ZyZW4=?=
Guest
Posts: n/a
 
      26th Jan 2007
Thanks for the help so far.

No, it can't handle my 4x49 array. The string can be maximum 253 char long.
Do you know if/how I can use 4 different 1D arrays (1x49) and assign them
one by one to each row in th 4x49 array?

I can't load data from the worksheet. I want my data to be hardcoded in the
VBA script.

Regards,
/Sören

"Bob Phillips" wrote:

> sval = "6,1,5,6;5,1,5,25;4,1,5,43;7,1,6,10;5,3,6,38;" & _
> "5,1,7,12;3,1,7,32;5,1,7,50;4,5,9,18;2,1,18,31;3,1,21" & _
> ",28;5,1,23,12"
> varr = Evaluate("{" & sval & "}")
>
> is a way to use continuations, but I think this method runs out of steam
> very quickly, it won't handle a 4x49 array.
>
> For that I think you would be best to load a worksheet range, and load from
> there.
>
> --
> ---
> HTH
>
> Bob
>
> (change the xxxx to gmail if mailing direct)
>
>
> "Sören_Marodören" <(E-Mail Removed)> wrote in message
> news:60CE796C-0E94-4821-8EBD-(E-Mail Removed)...
> > Hi,
> >
> > Assigning small 2D arrays is easy.
> > This is a 3x6 array:
> > Array_A = [{1, 3, 6, 10, 0, 0; 1, 1.2, 4.5, 6.8, 9.2, 10; 0, 0, 0, 0, 2,
> > 3}]
> > Every line is separated by ";".
> >
> > But when I type in bigger arrays and cut the line with a " _", as I do for
> > all other lines in the code that becomes to long, I get an error message,
> > "Missing end bracket"
> > Can anyone tell me why this doesn't work?
> >
> > How can I assign a 4x49 (or even 4x97) element array?
> >
> > I can assign 1D arrays with 49 elements, but is it possible to build a 2D
> > array out of these 1D arrays? Is that a way to get round the probelm?
> >
> > I have also problem with dimensioning these arrays.
> > When I write
> > Dim Array_A(1 To 4, 1 To 49) As Variant
> > I get an error "Can't assign to an array" when I Assign to the array

>
>
>

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      26th Jan 2007
This worked for me in VBS

Dim arr(3, 3)
For k = 0 To 3
Select Case k
Case 0
v = Array(11, _
12, _
13, _
14)
Case 1
v = Array(21, 22, 23, 24)
Case 2
v = Array(31, 32, 33, 34)
Case 3
v = Array(41, 42, 43, 44)
Case 4
End Select
For i = 0 To 3
arr(k, i) = v(i)
Next
Next

MsgBox arr(0, 0) & vbCr & arr(3, 3), , "my VBS array"

Regards,
Peter T


"Sören_Marodören" <(E-Mail Removed)> wrote in message
news:5881B563-85BC-4EC0-846C-(E-Mail Removed)...
> Thanks for the help so far.
>
> No, it can't handle my 4x49 array. The string can be maximum 253 char

long.
> Do you know if/how I can use 4 different 1D arrays (1x49) and assign them
> one by one to each row in th 4x49 array?
>
> I can't load data from the worksheet. I want my data to be hardcoded in

the
> VBA script.
>
> Regards,
> /Sören
>
> "Bob Phillips" wrote:
>
> > sval = "6,1,5,6;5,1,5,25;4,1,5,43;7,1,6,10;5,3,6,38;" & _
> > "5,1,7,12;3,1,7,32;5,1,7,50;4,5,9,18;2,1,18,31;3,1,21" & _
> > ",28;5,1,23,12"
> > varr = Evaluate("{" & sval & "}")
> >
> > is a way to use continuations, but I think this method runs out of steam
> > very quickly, it won't handle a 4x49 array.
> >
> > For that I think you would be best to load a worksheet range, and load

from
> > there.
> >
> > --
> > ---
> > HTH
> >
> > Bob
> >
> > (change the xxxx to gmail if mailing direct)
> >
> >
> > "Sören_Marodören" <(E-Mail Removed)> wrote in

message
> > news:60CE796C-0E94-4821-8EBD-(E-Mail Removed)...
> > > Hi,
> > >
> > > Assigning small 2D arrays is easy.
> > > This is a 3x6 array:
> > > Array_A = [{1, 3, 6, 10, 0, 0; 1, 1.2, 4.5, 6.8, 9.2, 10; 0, 0, 0, 0,

2,
> > > 3}]
> > > Every line is separated by ";".
> > >
> > > But when I type in bigger arrays and cut the line with a " _", as I do

for
> > > all other lines in the code that becomes to long, I get an error

message,
> > > "Missing end bracket"
> > > Can anyone tell me why this doesn't work?
> > >
> > > How can I assign a 4x49 (or even 4x97) element array?
> > >
> > > I can assign 1D arrays with 49 elements, but is it possible to build a

2D
> > > array out of these 1D arrays? Is that a way to get round the probelm?
> > >
> > > I have also problem with dimensioning these arrays.
> > > When I write
> > > Dim Array_A(1 To 4, 1 To 49) As Variant
> > > I get an error "Can't assign to an array" when I Assign to the array

> >
> >
> >



 
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
Converting native arrays to managed arrays Bob Altman Microsoft VC .NET 8 27th Feb 2008 11:33 PM
Jagged Arrays Problem - How to Assign Arrays to an Array Zigs Microsoft Excel Programming 3 11th Apr 2007 01:39 AM
Arrays - declaration, adding values to arrays and calculation Maxi Microsoft Excel Programming 1 17th Aug 2006 04:13 PM
Assigning arrays to report detail data rows =?Utf-8?B?Sm9obiBIIFc=?= Microsoft Access Reports 0 18th Apr 2005 10:37 PM
Assigning range names to arrays Kurt Krueger Microsoft Excel Programming 2 25th Aug 2004 01:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:58 PM.