PC Review


Reply
Thread Tools Rate Thread

Classes and Namespaces

 
 
tshad
Guest
Posts: n/a
 
      26th Apr 2007
I have a .dll that has MyFunctions as a Namespace and Class of FWData.

If I have my using statement as:

using MyFunctions.FWData

Why do I have to set a new variable as:

Dim fw = New MyFunctions.FWData(10)

Why can't I do:

Dim fw = new FWData(10)

This gives me an error:

C:\VSProjects\TestFWData\Form1.vb(73): Type 'FWData' is not defined.

Why is that? If I have it defined in my using statement - why do I need the
namespace?

The whole code is:

*******************************************************
Imports MyFunctions.FWData

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim fw = New MyFunctions.FWData(10)
Dim j As Integer = fw.ErrorCode
End Sub
End Class
******************************************************

Thanks,

Tom


 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      26th Apr 2007
Not sure why you are referring to "using" when it is "imports" that we are
discussing, but anyway, don't import the class, just the namespace. Then
your code would be:

*******************************************************
Imports MyFunctions

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim fw = New FWData(10)
Dim j As Integer = fw.ErrorCode
End Sub
End Class
******************************************************

When you import a namespace, you no longer have to fully qualify statements
that include elements of that imported namespace. If you import a class,
you can access certain elements of the class without fully qualifying them.

Your idea doesn't work because if you import this way:

Imports MyFunctions.FWData

You can now get at certain FWData class members without having to qualify
"MyFunctions.FWData".

But, when you write:

Dim fw = new FWData(10)

FWData is not found because the namespace that contains FWData has not been
imported, you are importing PAST that level.



"tshad" <(E-Mail Removed)> wrote in message
news:O12F$(E-Mail Removed)...
>I have a .dll that has MyFunctions as a Namespace and Class of FWData.
>
> If I have my using statement as:
>
> using MyFunctions.FWData
>
> Why do I have to set a new variable as:
>
> Dim fw = New MyFunctions.FWData(10)
>
> Why can't I do:
>
> Dim fw = new FWData(10)
>
> This gives me an error:
>
> C:\VSProjects\TestFWData\Form1.vb(73): Type 'FWData' is not defined.
>
> Why is that? If I have it defined in my using statement - why do I need
> the namespace?
>
> The whole code is:
>
> *******************************************************
> Imports MyFunctions.FWData
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Dim fw = New MyFunctions.FWData(10)
> Dim j As Integer = fw.ErrorCode
> End Sub
> End Class
> ******************************************************
>
> Thanks,
>
> Tom
>



 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      26th Apr 2007
On Apr 25, 8:36 pm, "tshad" <t...@home.com> wrote:
> I have a .dll that has MyFunctions as a Namespace and Class of FWData.
>
> If I have my using statement as:
>
> using MyFunctions.FWData
>
> Why do I have to set a new variable as:
>
> Dim fw = New MyFunctions.FWData(10)
>
> Why can't I do:
>
> Dim fw = new FWData(10)
>
> This gives me an error:
>
> C:\VSProjects\TestFWData\Form1.vb(73): Type 'FWData' is not defined.
>
> Why is that? If I have it defined in my using statement - why do I need the
> namespace?
>
> The whole code is:
>
> *******************************************************
> Imports MyFunctions.FWData
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Dim fw = New MyFunctions.FWData(10)
> Dim j As Integer = fw.ErrorCode
> End Sub
> End Class
> ******************************************************
>
> Thanks,
>
> Tom


> If I have my using statement as:
>
> using MyFunctions.FWData


I think you mean Imports as you're in the VB newsgroup and not the C#
one....

> Why is that? If I have it defined in my using statement - why do I need the
> namespace?


You Imported the FWData class, not the MyFunctions namespace.
Therefore it will allow "easy" access to any member of FWData, but to
get it recognize the members of MyFunctions you need to import it
also.

i.e. Change

> Imports MyFunctions.FWData


to

Imports MyFunctions
Imports MyFunctions.FWData

Thanks,

Seth Rowe

 
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
VB.NET classes, imports, and namespaces douglass_davis@earthlink.net Microsoft Dot NET 6 16th Oct 2006 07:26 PM
Partial Classes across different namespaces ? vivekian Microsoft C# .NET 3 16th Oct 2006 02:29 AM
Assemblies, Namespaces,classes =?Utf-8?B?Sm9zZW1h?= Microsoft C# .NET 1 28th Apr 2005 10:34 AM
About Classes and Namespaces TonyMX Microsoft ASP .NET 0 14th Mar 2004 05:41 AM
Classes and Namespaces Michael C Microsoft C# .NET 3 21st Feb 2004 07:34 PM


Features
 

Advertising
 

Newsgroups
 


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