Results 1 to 7 of 7

Thread: some problems with VB .NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    5

    some problems with VB .NET

    Hello!

    I have problems with this code:
    VB Code:
    1. Public Interface IPhone
    2.  
    3.     Enum CallState As Integer
    4.         Idle        
    5.         Dialing    
    6.         Ringing    
    7.         Speaking  
    8.     End Enum
    9.  
    10.     Enum CallResult As Integer
    11.         Normal      
    12.         NoCustomer  
    13.         NoRing      
    14.         [Error]      
    15.     End Enum
    16.  
    17.     Sub Dial(ByVal telephoneNo As String)
    18.     Sub Hangup()
    19.     Property State() As CallState
    20.     Property LastResult() As CallResult
    21.  
    22. End Interface
    23.  
    24. Public Class MyPhone
    25.     Inherits Form1
    26.     Implements IPhone
    27.  
    28.     Dim linea As AxetTT37.AxetLine
    29.     Dim CallState As IPhone.CallState
    30.  
    31.     Private _state As IPhone.CallState = CallState.Idle
    32.  
    33.     Public Sub [New]()
    34.         linea = New AxetTT37.AxetLine
    35.         linea.DeviceName = "AVM ISDN TAPI Services (Cntrl 1)"    
    36.         linea.DeviceActive = True
    37.     End Sub
    38.  
    39.      ReadOnly Property State() As IPhone.CallState Implements IPhone.State
    40.       Get
    41.           Return _state
    42.    End Get
    43.    End Property
    44.  
    45.     Public Sub Dial(ByVal telephoneNo As String) Implements IPhone.Dial
    46.         linea.CallPhoneNumber = telephoneNo
    47.         linea.CallDial()
    48.         _state = CallState.Dialing
    49.     End Sub
    50.  
    51.     Public Sub Hangup() Implements IPhone.Hangup
    52.         If linea.CallActive Then    
    53.             linea.CallHangup()      
    54.             linea.CallActive = False
    55.             _state = CallState.Idle
    56.         End If
    57.     End Sub
    58.  
    59. End Class

    1. I get these errors:
    In line: ReadOnly Property State() As IPhone.CallState Implements IPhone.State i got underlined IPhone.State() ->
    IPhone.State in State()
    Property: 'State' cannot implement 'State' because there is no matching property
    on Interface 'Iphone'

    - underlined IPhone when i define the class -> MyPhone must implement 'Propery State() As CallState' for interface Iphone

    How can i fix that?


    2. How can I access [New], Dial from class MyPhone in any other Form
    (like Form1...)?


    tnx for help

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    perhaps
    VB Code:
    1. Public Enum CallState As Integer
    2.    Idle
    3.    Dialing
    4.    Ringing
    5.    Speaking
    6. End Enum
    7.  
    8. Public Enum CallResult As Integer
    9.    Normal
    10.    NoCustomer
    11.    NoRing
    12.    [Error]
    13. End Enum
    14.  
    15. Public Interface IPhone
    16.  
    17.    Sub Dial(ByVal telephoneNo As String)
    18.    Sub Hangup()
    19.    Property State() As CallState
    20.    Property LastResult() As CallResult
    21.  
    22. End Interface
    23.  
    24. Public Class MyPhone
    25.    Inherits Form1
    26.    Implements IPhone
    27.  
    28.    Dim linea As AxetTT37.AxetLine
    29.    Dim CallState As IPhone.CallState
    30.  
    31.    Private _state As IPhone.CallState = CallState.Idle
    32.  
    33.    Public Sub [New]()
    34.       linea = New AxetTT37.AxetLine()
    35.       linea.DeviceName = "AVM ISDN TAPI Services (Cntrl 1)"
    36.       linea.DeviceActive = True
    37.    End Sub
    38.  
    39.    Property State() As CallState Implements IPhone.State
    40.       Get
    41.          Return _state
    42.       End Get
    43.       Set(ByVal Value As CallState)
    44.          ' blah
    45.       End Set
    46.    End Property
    47.  
    48.    ' implement this
    49.    Property lastresult() As CallResult Implements IPhone.LastResult
    50.       Get
    51.          ' blah
    52.       End Get
    53.       Set(ByVal Value As CallResult)
    54.          ' blah
    55.       End Set
    56.    End Property
    57.  
    58.    Public Sub Dial(ByVal telephoneNo As String) Implements IPhone.Dial
    59.       linea.CallPhoneNumber = telephoneNo
    60.       linea.CallDial()
    61.       _state = CallState.Dialing
    62.    End Sub
    63.  
    64.    Public Sub Hangup() Implements IPhone.Hangup
    65.       If linea.CallActive Then
    66.          linea.CallHangup()
    67.          linea.CallActive = False
    68.          _state = CallState.Idle
    69.       End If
    70.    End Sub
    71. End Class
    72.  
    73. ' sample class...
    74. Public Class SampleClass
    75.    Dim p As New MyPhone()
    76.    Sub New()
    77.       p.[New]() ' call the new method
    78.    End Sub
    79. End Class

  3. #3
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    1. Either in your Inteface IPhone add a readonly attribute for State, or in your MyPhone class remove the readonly attribute from the property and define a set.

    2. You need to assign a reference somehow in the other form.

    Either..

    VB Code:
    1. Private m_PhoneForm As MyPhone
    2.  
    3. Public Sub New(ByVal phoneForm As MyPhone)
    4.       m_PhoneForm = phoneForm

    Or

    Making the new form have a property and assigning the form to that property once you have created it.

    VB Code:
    1. 'Assuming in instance of MyPhone
    2.  
    3. Dim newForm As New FormB
    4.  
    5. newForm.PhoneForm = Me
    6.  
    7. newForm.Show

    Then all you need to do is use the private member.

    VB Code:
    1. m_PhoneForm.[New]
    2. m_PhoneForm.Dial

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    5
    tnx for help Carnifex.

    I fixed the problem with Interface.

    Now I have completed writing MyPhone class. So i want it to use now.
    What is the right way of doing that?

    In Form1 i added an ActiveX component,
    and MyPhone class Inherits Form1(this component).

    Can I now use MyPhone in Form1 or must I add New Form to my project?...
    I don't know what is the "standard".


    I tryed by adding a new Form(Form2.vb) into my project:
    VB Code:
    1. Public Class Form2
    2.     Inherits System.Windows.Forms.Form
    3. Private m_PhoneForm As MyPhone
    4.     Public Sub New(ByVal phoneForm As MyPhone)
    5.         m_PhoneForm = phoneForm
    6.     End Sub
    7.  
    8.  
    9. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    10.         m_PhoneForm.[New]()
    11.         m_PhoneForm.Dial("031219202")
    12.     End Sub
    13. End Class


    I get this error in line m_PhoneForm[New]() when i try to run the project:
    An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication10.exe

    Additional information: Object reference not set to an instance of an object.

  5. #5
    Member
    Join Date
    Apr 2004
    Location
    Millbrae, CA
    Posts
    48
    Might be a dumb question, but what is [New]? Or are the braces not suppose to be there?

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    5
    because New is a reserved word i use [New]

    I saw that in some examples...

  7. #7
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    You seem to have things correctly done w1nd. If I were you I would run thru the debugger and see what object is null (nothing).

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