Using a Two Dimensional Array

Now that you know how to programmatically produce a list (a one-dimensional array), it's time to take a closer look at how you can work with tables of data. The following hands-on creates a two-dimensional array that will hold a country or region name, name of currency, and exchange rate for three countries.

©Hands-On 7-5: Using a Two-Dimensional Array

1. In the Visual Basic Editor window, insert a new module.

2. Enter the following Exchange procedure in the module's Code window.

3. Execute the Exchange procedure (choose Run | Run Sub/UserForm).

Sub Exchange()

Dim t As String Dim r As String Dim Ex(3, 3) As Variant t = Chr(9) ' Tab r = Chr(13) ' Enter

MsgBox "Country " & t & t & "Currency" & t & t & "Value per US$" _ & r & r _

& Ex(1, 1) & t & t & Ex(1, 2) & t & Ex(1, 3) & r _ & Ex(2, 1) & t & t & Ex(2, 2) & t & t & Ex(2, 3) & r _ & Ex(3, 1) & t & t & Ex(3, 2) & t & Ex(3, 3), , _ "Exchange"

End Sub

When you run the Exchange procedure, you will see a message box with the information presented in three columns (see Figure 7-2).

Introduction to Access 2003 VBA Programming

0 0

Post a comment