Creating a new object

  • Thread starter Thread starter KM
  • Start date Start date
K

KM

Hi group

I´ve created a new class but I can´t seem to access any of the public
subs in the class. The class:

Public Class testClass
Public iTest As Integer
Public Sub New()
iTest = 0
End Sub

Public Sub add()
iTest = iTest + 1
End Sub

Public Function returnValue() As Integer
Return iTest
End Function
End Class

I would imagine, that this is the way to use this class in a form:
dim myTestClass as testClass = new testClass

and then something like:

myTestClass.add()
dim i as integer
i = myTestClass.returnValue()

Any suggestions would be greatly appreciated

TIA
Kaare
 
So what error do you get, on what line and is it at compile time or at
runtime?

Cheers
Daniel
 
Did intellisense (the dropdown as you called it), show you "testClass" after
you typed "New"?

If not then this is probably a namespace problem. The calling and server
code have to be in the same namespace or the calling code has to import the
namespace. Look in Class View or object browser to see which namespace your
form is and which one your testClass is.

If the above doesn't lead you to a resolution, post the complete project so
I can look at it.

Cheers
Daniel
 
Daniel said:
So what error do you get, on what line and is it at compile time or at
runtime?

Cheers
Daniel
Thanks for your reply Daniel

Here is the form, where I want to use my testClass
There is no actual error - Visual Studio just doesn´t show any
methods in the autocompletion dropdown.

Perhaps it´s a miscomfiguration i VS?

Public Class GpsTest
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Text = "GpsTest"
End Sub

#End Region
Dim oTestClass As testClass = New testClass


End Class
 
Daniel said:
Did intellisense (the dropdown as you called it), show you "testClass" after
you typed "New"?
it does - but I would expect, that when I type "oTestClass" followed by
a dot, the public methods in testClass would appear in intellisense (at
least when I press ctrl+space). Pressing ctrl+space resolves in an
intellisense dropdown with all types of object (basically all available
classes in compact framework)
If not then this is probably a namespace problem. The calling and server
code have to be in the same namespace or the calling code has to import the
namespace. Look in Class View or object browser to see which namespace your
form is and which one your testClass is. They are in the same namespace

If the above doesn't lead you to a resolution, post the complete project so
I can look at it.

Cheers
Daniel
Thanks for your help
 
The original code you posted does not show *where* you are trying to access
members of oTestClass.

Add a method to your form e.g.
Public Sub SomeMethod
' intellisense on the next line
oTestClass.
End Sub

Does the above work? Again, if not then post your project so I can have a
look at it...

Cheers
Daniel
 
Daniel said:
The original code you posted does not show *where* you are trying to access
members of oTestClass.

Add a method to your form e.g.
Public Sub SomeMethod
' intellisense on the next line
oTestClass.
End Sub
That did the trick. THanks for your help
 
Back
Top