Results 1 to 7 of 7

Thread: Need Help with array

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Need Help with array

    Hi guys,

    I've built a telephone application but I'm coming unstuck with the array and how to work with it as it's new to me.

    Here is how the program is set out I have two classes one for the Phone and one for an exchange that makes the phone.

    The array is in the exchange so when a new phone is created it is added to the exchange and listed by a number value i.e 0 = 111 1 = 222 etc.

    I have got the phone working so it will ring another phone and answer but I'm having issues getting the 3rd phone to see that the 1st phone is engaged and to return a busy signal to the 3rd phone.

    Can anyone give me an idea how to do this? As you can tell I'm still very new and this is the first time I've had to work with using a class with the form.

    Kind Regards
    x-2o

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Need Help with array

    Give the phone class a Busy property...
    Code:
    If cPhone(36).Busy = True then...
    If you can post what you have then we have a better idea of what is going on.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Re: Need Help with array

    The way I have it setup is like this:

    Exchange.vb
    NetPhone.vb

    Cl_Exchange.vb which is the class
    Cl_Phone.vb which is the second class

    The exchange has a public function to show the phone location in the array

    This code is in the Cl_Exchange
    Code:
    Public Function whereAmI_inarray(ByVal telNum As String) As Integer
            Dim Counter As Integer
            For Counter = 1 To PhoneArray.Count - 1
                If PhoneArray(Counter).whoami = telNum Then
                    Return Counter
                End If
            Next
        End Function
    This links in to this bit of code in Cl_Phone

    Code:
    Public Sub GetMyLocationFromExchange()
            MyLocationInExchange = c_exchange.whereAmI_inarray(myNumber)
    
        End Sub
    The code above tells the phone being used to dial out where it is in the array the code below looks where the other phone that is being dialed is which is also in the Cl_Phone:

    Code:
    Public Sub GetCallingLocationFromExchange(ByVal num)
            CalledLocationInExchange = c_exchange.whereAmI_inarray(num)
            Me.c_exchange.callPhone(CalledLocationInExchange)
    
        End Sub
    That uses the same code in the Cl_Exchange to find the location then I have added another bit of code to activate the ring out class in the Cl_Phone.

    This is in the Cl_Exchange:
    Code:
        Public Sub callPhone(ByVal location As Integer)
            PhoneArray(location).ring()
        End Sub
    I will leave it at that for now.
    Thanks for the response

    Regards
    x-2o

  4. #4

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Re: Need Help with array

    Windows Studio 2005 windows application

  6. #6

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need Help with array

    You're going about this all wrong. You should start with a Phone class:
    vb.net Code:
    1. Public Class Phone
    2.  
    3.     'Member declarations here.
    4.  
    5. End Class
    You should then define a class that represents a collection of Phone objects:
    vb.net Code:
    1. Public Class PhoneCollection
    2.     Inherits System.Collections.ObjectModel.Collection(Of Phone)
    3. End Sub
    The PhoneCollection inherits everything it needs from the Collection class, like Add and Remove methods and an Item property. You would then declare a property in your Exchange class of that type:
    vb.net Code:
    1. Public Class Exchange
    2.  
    3.     Private _phones As New PhoneCollection
    4.  
    5.     Public ReadOnly Property Phones() As PhoneCollection
    6.         Get
    7.             Return Me._phones
    8.         End Get
    9.     End Property
    10.  
    11.     'Other declarations here.
    12.  
    13. End Class
    You would then add a new Phone to an Exchnage like this:
    vb.net Code:
    1. Dim myPhone As New Phone
    2.  
    3. myExchange.Phones.Add(myPhone)
    The PhoneCollection already has a IndexOf method too, so your method with the silly name is not required.

    You could then add a method to your PhoneCollection named FindByNumber that would find a Phone object given a phone number. Etc., etc.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width