|
-
Jul 18th, 2004, 07:02 PM
#1
Thread Starter
New Member
some problems with VB .NET
Hello!
I have problems with this code:
VB Code:
Public Interface IPhone
Enum CallState As Integer
Idle
Dialing
Ringing
Speaking
End Enum
Enum CallResult As Integer
Normal
NoCustomer
NoRing
[Error]
End Enum
Sub Dial(ByVal telephoneNo As String)
Sub Hangup()
Property State() As CallState
Property LastResult() As CallResult
End Interface
Public Class MyPhone
Inherits Form1
Implements IPhone
Dim linea As AxetTT37.AxetLine
Dim CallState As IPhone.CallState
Private _state As IPhone.CallState = CallState.Idle
Public Sub [New]()
linea = New AxetTT37.AxetLine
linea.DeviceName = "AVM ISDN TAPI Services (Cntrl 1)"
linea.DeviceActive = True
End Sub
ReadOnly Property State() As IPhone.CallState Implements IPhone.State
Get
Return _state
End Get
End Property
Public Sub Dial(ByVal telephoneNo As String) Implements IPhone.Dial
linea.CallPhoneNumber = telephoneNo
linea.CallDial()
_state = CallState.Dialing
End Sub
Public Sub Hangup() Implements IPhone.Hangup
If linea.CallActive Then
linea.CallHangup()
linea.CallActive = False
_state = CallState.Idle
End If
End Sub
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
-
Jul 18th, 2004, 08:32 PM
#2
Fanatic Member
perhaps
VB Code:
Public Enum CallState As Integer
Idle
Dialing
Ringing
Speaking
End Enum
Public Enum CallResult As Integer
Normal
NoCustomer
NoRing
[Error]
End Enum
Public Interface IPhone
Sub Dial(ByVal telephoneNo As String)
Sub Hangup()
Property State() As CallState
Property LastResult() As CallResult
End Interface
Public Class MyPhone
Inherits Form1
Implements IPhone
Dim linea As AxetTT37.AxetLine
Dim CallState As IPhone.CallState
Private _state As IPhone.CallState = CallState.Idle
Public Sub [New]()
linea = New AxetTT37.AxetLine()
linea.DeviceName = "AVM ISDN TAPI Services (Cntrl 1)"
linea.DeviceActive = True
End Sub
Property State() As CallState Implements IPhone.State
Get
Return _state
End Get
Set(ByVal Value As CallState)
' blah
End Set
End Property
' implement this
Property lastresult() As CallResult Implements IPhone.LastResult
Get
' blah
End Get
Set(ByVal Value As CallResult)
' blah
End Set
End Property
Public Sub Dial(ByVal telephoneNo As String) Implements IPhone.Dial
linea.CallPhoneNumber = telephoneNo
linea.CallDial()
_state = CallState.Dialing
End Sub
Public Sub Hangup() Implements IPhone.Hangup
If linea.CallActive Then
linea.CallHangup()
linea.CallActive = False
_state = CallState.Idle
End If
End Sub
End Class
' sample class...
Public Class SampleClass
Dim p As New MyPhone()
Sub New()
p.[New]() ' call the new method
End Sub
End Class
-
Jul 18th, 2004, 08:34 PM
#3
Addicted Member
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:
Private m_PhoneForm As MyPhone
Public Sub New(ByVal phoneForm As MyPhone)
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:
'Assuming in instance of MyPhone
Dim newForm As New FormB
newForm.PhoneForm = Me
newForm.Show
Then all you need to do is use the private member.
VB Code:
m_PhoneForm.[New]
m_PhoneForm.Dial
-
Jul 19th, 2004, 08:48 AM
#4
Thread Starter
New Member
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:
Public Class Form2
Inherits System.Windows.Forms.Form
Private m_PhoneForm As MyPhone
Public Sub New(ByVal phoneForm As MyPhone)
m_PhoneForm = phoneForm
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_PhoneForm.[New]()
m_PhoneForm.Dial("031219202")
End Sub
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.
-
Jul 19th, 2004, 09:15 AM
#5
Member
Might be a dumb question, but what is [New]? Or are the braces not suppose to be there?
-
Jul 19th, 2004, 02:04 PM
#6
Thread Starter
New Member
because New is a reserved word i use [New]
I saw that in some examples...
-
Jul 19th, 2004, 06:25 PM
#7
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|