PC Review


Reply
Thread Tools Rate Thread

Creating a new object

 
 
KM
Guest
Posts: n/a
 
      28th Apr 2005
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
 
Reply With Quote
 
 
 
 
Daniel Moth
Guest
Posts: n/a
 
      28th Apr 2005
So what error do you get, on what line and is it at compile time or at
runtime?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"KM" <(E-Mail Removed)> wrote in message
news:ev0T9Z%(E-Mail Removed)...
> 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


 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      28th Apr 2005
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
--
http://www.danielmoth.com/Blog/
"KM" <(E-Mail Removed)> wrote in message
news:%231F2il%(E-Mail Removed)...
> Daniel Moth wrote:
>
>> Show us the code and give us details on the error including what line it
>> occurred on.
>>
>> 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
>


 
Reply With Quote
 
KM
Guest
Posts: n/a
 
      28th Apr 2005
Daniel Moth wrote:

> 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

 
Reply With Quote
 
KM
Guest
Posts: n/a
 
      28th Apr 2005
Daniel Moth wrote:

> 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
 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      28th Apr 2005
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
--
http://www.danielmoth.com/Blog/


"KM" <(E-Mail Removed)> wrote in message
news:%23Hs$P2%(E-Mail Removed)...
> Daniel Moth wrote:
>
>> 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


 
Reply With Quote
 
KM
Guest
Posts: n/a
 
      28th Apr 2005
Daniel Moth wrote:

> 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
>
> Does the above work? Again, if not then post your project so I can have a
> look at it...
>
> Cheers
> Daniel
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a derived object from a based object Warren Microsoft C# .NET 9 11th Mar 2009 12:15 PM
Creating a derived object from a base object benliu Microsoft C# .NET 10 6th Dec 2006 11:18 AM
Creating object of another object Maziar Aflatoun Microsoft ASP .NET 1 6th Apr 2005 03:25 PM
Getting object type without creating object Raghu Microsoft VB .NET 6 24th Aug 2004 10:25 PM
Why Creating object failed even I set a reference to this object? Shu Microsoft Excel Programming 3 9th Mar 2004 03:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:25 AM.