• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Arrays

I am trying to make a program of a telephone which has an add to memory and a memory recall button that stores 10 names and numbers and then displays them, if for example I press Memory 1.  I can get the program to add to memory, but if I add more than one record I can't get the display to show the name and number. I don't really know much about arrays.  Where have I gone wrong with the programming?
0
Boon
Asked:
Boon
  • 3
1 Solution
 
VbmasterCommented:
"My program won't work. What's wrong?".. I don't think noone can help you much here, because you do not show anything of the code you use now. If you want I can have a look to see what the problem is (my email is mfitcom_suger@hotmail.com).

One reason for the problem you have can be that you redim a array with ReDim when you should use ReDim Preserve (look in the help file if you do not know what Preserve means).
0
 
mcriderCommented:
Here is an example of how you can store 10 names and numbers in an array, then retrieve them...


1) Create a new project.

2) Add 2 command buttons to the project.

3) Add a MODULE to the project and add the following code to the module:

   Public PhoneMemory(1 To 10, 1 To 2) As String

4) Add the following code to the DECLARATION SECTION of Form1:

    Private Sub Command1_Click()
        'Load Name and Numbers
        PhoneMemory(1, 1) = "Marvin"
        PhoneMemory(1, 2) = "555-1111"
       
        PhoneMemory(2, 1) = "Steve"
        PhoneMemory(2, 2) = "555-2222"
       
        PhoneMemory(3, 1) = "Mary"
        PhoneMemory(3, 2) = "555-3333"
       
        PhoneMemory(4, 1) = "Jessie"
        PhoneMemory(4, 2) = "555-4444"
       
        PhoneMemory(5, 1) = "Allen"
        PhoneMemory(5, 2) = "555-5555"
       
        PhoneMemory(6, 1) = "Betsy"
        PhoneMemory(6, 2) = "555-6666"
       
        PhoneMemory(7, 1) = "Hal"
        PhoneMemory(7, 2) = "555-7777"
       
        PhoneMemory(8, 1) = "Mickey"
        PhoneMemory(8, 2) = "555-8888"
       
        PhoneMemory(9, 1) = "Birdie"
        PhoneMemory(9, 2) = "555-9999"
       
        PhoneMemory(10, 1) = "David"
        PhoneMemory(10, 2) = "555-0000"
    End Sub
    Private Sub Command2_Click()
        'Display all of the stored numbers to the debug window
        Dim iVal As Integer
        For iVal = 1 To 10
            Debug.Print "Stored Name #" & iVal & ": " & PhoneMemory(iVal, 1)
            Debug.Print "Phone #" & iVal & ": " & PhoneMemory(iVal, 2)
            Debug.Print " "
        Next iVal
    End Sub

5) Run the program.

6) Click Command1 to load the names & numbers.

7) Click Command2 to show the loaded names and numbers in the debug window.


Hope this helps!


Cheers!


0
 
BoonAuthor Commented:
Thank you so much.
0
 
mcriderCommented:
Glad I could help! Thanks for the points!


Cheers!
0
 
mcriderCommented:
Boon,

You still have a duplicate of this question open at http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10256751 

If you want your 100 points back, go delete this question...


Cheers!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now