473,734 Members | 2,724 Online

# Q on the Array function...

How would I modify the following to achieve a 2-dimensional array?

Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
' Return values assume lower bound set to 1 (using Option Base
' statement).
MyDay = MyWeek(2) ' MyDay contains "Tue".
MyDay = MyWeek(4) ' MyDay contains "Thu".

In other words, I want the array to hold
"Monday","Segun da-feira"
"Tuesday","Terc a-feira"
"Wednesday","Qu arta-feira"
"Thursday","Qui nta-feira"
....
Aug 31 '06 #1
26 2744
MLH wrote:
How would I modify the following to achieve a 2-dimensional array?

Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
' Return values assume lower bound set to 1 (using Option Base
' statement).
MyDay = MyWeek(2) ' MyDay contains "Tue".
MyDay = MyWeek(4) ' MyDay contains "Thu".

In other words, I want the array to hold
"Monday","Segun da-feira"
"Tuesday","Terc a-feira"
"Wednesday","Qu arta-feira"
"Thursday","Qui nta-feira"
Why bother?
Put the data in a table and forget the array.
Or use a collection with Monday as the key and Segunda-feira
as the value.
Or create a UDT with members for English and Portuguese and
whatever other language you want and put them in a collection.
Or just about anything but a muli-dimensional array.
Aug 31 '06 #2
MLH wrote:
How would I modify the following to achieve a 2-dimensional array?

Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
' Return values assume lower bound set to 1 (using Option Base
' statement).
MyDay = MyWeek(2) ' MyDay contains "Tue".
MyDay = MyWeek(4) ' MyDay contains "Thu".

In other words, I want the array to hold
"Monday","Segun da-feira"
"Tuesday","Terc a-feira"
"Wednesday","Qu arta-feira"
"Thursday","Qui nta-feira"
...
You're not looking for a 2d array, you're looking for 2x1d arrays with
coordinated indexes, which as rkc mentioned, would be much better
represented by other means.

--
Smartin
Aug 31 '06 #3
What would a multi-dimensional array be useful for
and why has it continued to be supported in all
successive releases of Access?

One thing, like variables - its not a requirement to
write it to disk.Imagine the headaches of declaring
50 variables as opposed to a 5x10 array.

And if there really were a substantial good reason for using an array,
how would I modify the following to achieve a 2-dimensional array?

Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
' Return values assume lower bound set to 1 (using Option Base
' statement).
MyDay = MyWeek(2) ' MyDay contains "Tue".
MyDay = MyWeek(4) ' MyDay contains "Thu".
Aug 31 '06 #4
I sort-a-get what you guys are saying, but am
struggling a bit. Pardon the seeming uselessness
of the following example and allow me to illustrate
my question in more detail.

Private Sub Command0_Click( )
Dim i As Integer, j As Integer, PString As String
Dim WeekDays(6, 1) 'This is the 7x2 array (at least, I thought it
was)

WeekDays(0, 0) = "Sunday"
WeekDays(0, 1) = "Domingo"
WeekDays(1, 0) = "Monday"
WeekDays(1, 1) = "Segunda-feira"
WeekDays(2, 0) = "Tuesday"
WeekDays(2, 1) = "Terca-feira"
WeekDays(3, 0) = "Wednesday"
WeekDays(3, 1) = "Quarta-feira"
WeekDays(4, 0) = "Thursday"
WeekDays(4, 1) = "Quinta-feira"
WeekDays(5, 0) = "Friday"
WeekDays(5, 1) = "Sexta-feira"
WeekDays(6, 0) = "Saturday"

For i = LBound(WeekDays , 1) To UBound(WeekDays , 1)
For j = LBound(WeekDays , 2) To UBound(WeekDays , 2)
MsgBox WeekDays(i, j) 'MsgBox CStr(i) & ","
& CStr(j)
Next j
Next i

For i = LBound(WeekDays , 1) To UBound(WeekDays , 1)
PString = ""
For j = LBound(WeekDays , 2) To UBound(WeekDays , 2)
If PString = "" Then
PString = WeekDays(i, j)
Else
PString = PString & " ==" & WeekDays(i, j)
End If
Next j
MsgBox PString
Next i

End Sub

Is WeekDays not a 7x2 array? And, if not, what exactly is it
that makes it a 2x1d array instead?
Aug 31 '06 #5
MLH wrote:
What would a multi-dimensional array be useful for
and why has it continued to be supported in all
successive releases of Access?
I don't know... a checker board, I guess.
It's been supported since GW Basic I believe.
One thing, like variables - its not a requirement to
write it to disk.Imagine the headaches of declaring
50 variables as opposed to a 5x10 array.
Imagine there's no heaven. It's easy if you try. (J. Lennon)
And if there really were a substantial good reason for using an array,
how would I modify the following to achieve a 2-dimensional array?

Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
' Return values assume lower bound set to 1 (using Option Base
' statement).
MyDay = MyWeek(2) ' MyDay contains "Tue".
MyDay = MyWeek(4) ' MyDay contains "Thu".
You really can't use Array as you have used it to create a
2 dimensional array. You could create an array of arrays if
you really wanted to.

Dim varDow as Variant

varDow = Array _
(Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"), _
(Array("Segunda-feira", "Terca-feira", "Quarta-feira","Quinta-feira" _
"Sexta-feira", "blah", "blab"))

Dim varEnglish as Variant
Dim varPortuguese as Variant

varEnglish = varDow(1)
Debug.Print varEnglish(1) 'Monday
Debug.Print varEnglish(2) 'Tuesday

varPortuguese = varDow(2)
Debug.Print varPortuguese(1 ) 'Segunda-feira

Aug 31 '06 #6
On Thu, 31 Aug 2006 19:46:08 -0400, MLH <CR**@NorthStat e.netwrote:
>I sort-a-get what you guys are saying, but am
struggling a bit. Pardon the seeming uselessness
of the following example and allow me to illustrate
my question in more detail.

Private Sub Command0_Click( )
Dim i As Integer, j As Integer, PString As String
Dim WeekDays(6, 1) 'This is the 7x2 array (at least, I thought it
was)

WeekDays(0, 0) = "Sunday"
WeekDays(0, 1) = "Domingo"
WeekDays(1, 0) = "Monday"
WeekDays(1, 1) = "Segunda-feira"
WeekDays(2, 0) = "Tuesday"
WeekDays(2, 1) = "Terca-feira"
WeekDays(3, 0) = "Wednesday"
WeekDays(3, 1) = "Quarta-feira"
WeekDays(4, 0) = "Thursday"
WeekDays(4, 1) = "Quinta-feira"
WeekDays(5, 0) = "Friday"
WeekDays(5, 1) = "Sexta-feira"
WeekDays(6, 0) = "Saturday"

For i = LBound(WeekDays , 1) To UBound(WeekDays , 1)
For j = LBound(WeekDays , 2) To UBound(WeekDays , 2)
MsgBox WeekDays(i, j) 'MsgBox CStr(i) & ","
& CStr(j)
Next j
Next i

For i = LBound(WeekDays , 1) To UBound(WeekDays , 1)
PString = ""
For j = LBound(WeekDays , 2) To UBound(WeekDays , 2)
If PString = "" Then
PString = WeekDays(i, j)
Else
PString = PString & " ==" & WeekDays(i, j)
End If
Next j
MsgBox PString
Next i

End Sub

Is WeekDays not a 7x2 array? And, if not, what exactly is it
that makes it a 2x1d array instead?
I think what they are trying to tell you is that the Array function
returns a one dimension array. You wouldn't be able to populate a two
dimension array, using the Array function, to get the result you want.

The suggestions were to either put the data in a table and use it like
an array, or populate the array from the table, which could be done
with a single command. Or alternatively, use 2 single dimension
arrays.

I hope this helps to clear the confusion.

-=-=-=-=-=-=-=-=-=-=-=-=
Randy Harris
tech at promail dot com
Sep 1 '06 #7
MLH <CR**@NorthStat e.netwrote:
: How would I modify the following to achieve a 2-dimensional array?

: Dim MyWeek, MyDay
: MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
: ' Return values assume lower bound set to 1 (using Option Base
: ' statement).
: MyDay = MyWeek(2) ' MyDay contains "Tue".
: MyDay = MyWeek(4) ' MyDay contains "Thu".

: In other words, I want the array to hold
: "Monday","Segun da-feira"
: "Tuesday","Terc a-feira"
: "Wednesday","Qu arta-feira"
: "Thursday","Qui nta-feira"
: ...

Would a one-dimensional array do?

MyWeek = Array("Mon", "Tue", "Wed", "Thu", _
"Fri", "Sat", "Sun", "Segunda-feira", "Terca-feira", ...)

EnglishTue = MyWeek(1)
PortugueseTue = MyWeek(8)

In general:
EnglishDay = MyWeek(DayNumbe r)
PortugueseDay = MyWeek(DayNumbe r + 7)

--thelma
Sep 1 '06 #8
MLH wrote:
I sort-a-get what you guys are saying, but am
struggling a bit. Pardon the seeming uselessness
of the following example and allow me to illustrate
my question in more detail.

Private Sub Command0_Click( )
Dim i As Integer, j As Integer, PString As String
Dim WeekDays(6, 1) 'This is the 7x2 array (at least, I thought it
was)

WeekDays(0, 0) = "Sunday"
WeekDays(0, 1) = "Domingo"
WeekDays(1, 0) = "Monday"
WeekDays(1, 1) = "Segunda-feira"
WeekDays(2, 0) = "Tuesday"
WeekDays(2, 1) = "Terca-feira"
WeekDays(3, 0) = "Wednesday"
WeekDays(3, 1) = "Quarta-feira"
WeekDays(4, 0) = "Thursday"
WeekDays(4, 1) = "Quinta-feira"
WeekDays(5, 0) = "Friday"
WeekDays(5, 1) = "Sexta-feira"
WeekDays(6, 0) = "Saturday"

For i = LBound(WeekDays , 1) To UBound(WeekDays , 1)
For j = LBound(WeekDays , 2) To UBound(WeekDays , 2)
MsgBox WeekDays(i, j) 'MsgBox CStr(i) & ","
& CStr(j)
Next j
Next i

For i = LBound(WeekDays , 1) To UBound(WeekDays , 1)
PString = ""
For j = LBound(WeekDays , 2) To UBound(WeekDays , 2)
If PString = "" Then
PString = WeekDays(i, j)
Else
PString = PString & " ==" & WeekDays(i, j)
End If
Next j
MsgBox PString
Next i

End Sub

Is WeekDays not a 7x2 array? And, if not, what exactly is it
that makes it a 2x1d array instead?
Weekdays is a 7x2 array, but you didn't get there by
using the Array() function.

There are also much easier ways of managing the kind
of data you would use a multi-dimensional array for.

Sep 1 '06 #9
MLH <CR**@NorthStat e.netwrote:
: Dim WeekDays(6, 1) 'This is the 7x2 array (at least, I thought it
: was)
/\ You're actually defining a 6x1 array here.
|| Weekdays(7,2) defines a 7x2 array.

--thelma

Sep 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.