473,734 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q on the Array function...

MLH
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
rkc
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
MLH
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
MLH
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"
WeekDays(6, 1) = "Sabado"

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
rkc
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"
WeekDays(6, 1) = "Sabado"

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
rkc
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"
WeekDays(6, 1) = "Sabado"

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.

Similar topics

58
10167
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
11
39468
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not rst.EOF i = i + 1 If rst!Something = Then astrMyArray(i) = rst!Something
8
29062
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If possible how could one pass these seven values in the array to a function that would check the values. I tried return y but it didn't work
6
4151
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the end is found is less efficient than using sizeof operator , since size of the array is completely determined at compile time. i don't quite understand this. Could anyone explain to me in detail ?
7
3198
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends up looking for characters that wrap around the stripped characters and it ends up as a recursive ordeal that fails to identify a poorly constructed $_GET variable (when someone hand-types the item into the line and makes a simple typing error).
4
1984
by: assgar | last post by:
Hi Seasons Greetings Its back, I am being haunted. I thought I had resolved this problem but I am intermittently the receving the warnings below. This code consist of a 1) HTML form, 2) a display function on the HTML form and
14
20405
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is passed also. I understand that this way of passing the array is by value and if the prototype is declared as foo(int *), it is by reference in which case the value if modified in the function will get reflected in the main function as well. I dont...
7
8131
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h> #include<stdlib.h> #include<math.h>
9
2684
by: =?Utf-8?B?RGFya21hbg==?= | last post by:
Hi, I am wondering how you multi-dimension an array function? My declared function looks like this: Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long, ByVal Val3 As String) As String() Previously I dimensioned a single dimension Array to the size I wanted and
26
4872
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure about the syntax of calling the same. #include <stdio.h> void fp1()
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.