Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I
write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue
line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff 14 14004
Geoff,
"MyClass" is a reserved word, you cannot name a class the same as a reserved
word without "escaping" it, in VB.NET you use square brackets [] to "escape"
keywords.
Something like:
Public Class [MyClass]
End Class
Public x As New [MyClass]
Hope this helps
Jay
"Geoff Jones" <no********@email.com> wrote in message
news:41**********************@news.dial.pipex.com. .. Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff
Ah, sorry Jay, but I mislead you. Actually I've called the class:
SmoothProgressBar
and it still does it :( i.e. I typed myClass in the hope of simplifying
things. Sorry.
Geoff
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uV**************@TK2MSFTNGP14.phx.gbl... Geoff, "MyClass" is a reserved word, you cannot name a class the same as a reserved word without "escaping" it, in VB.NET you use square brackets [] to "escape" keywords.
Something like:
Public Class [MyClass] End Class
Public x As New [MyClass]
Hope this helps Jay
"Geoff Jones" <no********@email.com> wrote in message news:41**********************@news.dial.pipex.com. .. Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff
"Geoff Jones" <no********@email.com> schrieb: I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
'MyClass' is a keyword of VB.NET and thus cannot be used as a class name
unless you put it into square brackets:
Imports myClass
You don't need to import the class. Instead, import the namespace the class
is part of. I suggest not to name a class 'MyClass' and use a more
meaningful class name instead.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Okay, sorted it! I'd forgotten to add the namespace - D'OH!
Geoff
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uV**************@TK2MSFTNGP14.phx.gbl... Geoff, "MyClass" is a reserved word, you cannot name a class the same as a reserved word without "escaping" it, in VB.NET you use square brackets [] to "escape" keywords.
Something like:
Public Class [MyClass] End Class
Public x As New [MyClass]
Hope this helps Jay
"Geoff Jones" <no********@email.com> wrote in message news:41**********************@news.dial.pipex.com. .. Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff
Geoff,
Are you sure your class is public?
Cor
If you are importing myClass then myClass is a namespace. A namespace isn't
a type hence the error message. Is myClass actually a class? You defined
Public Class myClass somewhere?
You are basically trying to do this:
Dim x As New System.Windows.Forms
What you wanted to do was:
Dim x As New System.Windows.Forms.Form
Hope it helps some.
Chris
"Geoff Jones" <no********@email.com> wrote in message
news:41**********************@news.dial.pipex.com. .. Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff
Hi Cor
I'd forgotten to add the namespace. Sorted now.
Thanks for your suggestion.
Geoff
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Geoff,
Are you sure your class is public?
Cor
As per the posts above, I've solved it by writing:
Public x As New SmoothProgressBar.SmoothProgressBar
This now works i.e. the first part is the namespace, the next is the class.
Geoff
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:O5**************@TK2MSFTNGP15.phx.gbl... If you are importing myClass then myClass is a namespace. A namespace isn't a type hence the error message. Is myClass actually a class? You defined Public Class myClass somewhere?
You are basically trying to do this: Dim x As New System.Windows.Forms What you wanted to do was: Dim x As New System.Windows.Forms.Form
Hope it helps some. Chris
"Geoff Jones" <no********@email.com> wrote in message news:41**********************@news.dial.pipex.com. .. Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff
Geoff,
To avoid some subtle & potentially hard to follow ambiguity errors I avoid
naming a namespace the same as a Class name.
Hope this helps
Jay
"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ... As per the posts above, I've solved it by writing:
Public x As New SmoothProgressBar.SmoothProgressBar
This now works i.e. the first part is the namespace, the next is the class.
Geoff
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote in message news:O5**************@TK2MSFTNGP15.phx.gbl... If you are importing myClass then myClass is a namespace. A namespace isn't a type hence the error message. Is myClass actually a class? You defined Public Class myClass somewhere?
You are basically trying to do this: Dim x As New System.Windows.Forms What you wanted to do was: Dim x As New System.Windows.Forms.Form
Hope it helps some. Chris
"Geoff Jones" <no********@email.com> wrote in message news:41**********************@news.dial.pipex.com. .. Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff
Chris, If you are importing myClass then myClass is a namespace.
You can import either a Class or a Namespace!
Importing a class is handy when you want to access the Shared members of a
class without qualifying the identifiers with a class name. Which is similar
to simply defining the class as a Module (or better to get a C# class with
only static members to behave similar to a VB.NET module).
For example:
Imports System.Math
Public Module MainModule
Public Sub Main()
Dim x, y, z As Integer
x = 10
y = 11
z = Min(x, y)
End Sub
End Module
Notice that I used Math.Min without qualifying the Math class name. I
understand that C# 2.0 (VS.NET 2005, aka Whidbey, due out later in 2005)
will have a similar ability...
Hope this helps
Jay
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:O5**************@TK2MSFTNGP15.phx.gbl... If you are importing myClass then myClass is a namespace. A namespace isn't a type hence the error message. Is myClass actually a class? You defined Public Class myClass somewhere?
You are basically trying to do this: Dim x As New System.Windows.Forms What you wanted to do was: Dim x As New System.Windows.Forms.Form
Hope it helps some. Chris
"Geoff Jones" <no********@email.com> wrote in message news:41**********************@news.dial.pipex.com. .. Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff
Hi Jay
This is still puzzling me slightly - although the code is now working. The
class i.e. SmoothProgressBar, does not have a namespace explicitly in the
code. So, as I have already mentioned, I can only get the code to compile if
I write
Dim x As New SmoothProgressBar.SmoothProgressBar
Is the namespace implicitly set to the name of the class?
I take your point about the namespace and the class name being the same - if
only because it appears overkill and a lot of unnecessary typing.
Interestingly enough, when I wrap the class in my own namespace e.g.
Namespace MyUtilityCollection
' The SmoothProgressBar class
End Namespace
I can call the tool by using
Dim x As New MyUtilityCollection.SmoothProgressBar
Which is less confusing!
Can anybody explain if the namespace is set implictly to the name of the
class and if not why it appears to be happening in my application?
Thanks in advance
Geoff
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uY**************@TK2MSFTNGP14.phx.gbl... Geoff, To avoid some subtle & potentially hard to follow ambiguity errors I avoid naming a namespace the same as a Class name.
Hope this helps Jay
"Geoff Jones" <no********@email.com> wrote in message news:41***********************@news.dial.pipex.com ... As per the posts above, I've solved it by writing:
Public x As New SmoothProgressBar.SmoothProgressBar
This now works i.e. the first part is the namespace, the next is the class.
Geoff
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote in message news:O5**************@TK2MSFTNGP15.phx.gbl... If you are importing myClass then myClass is a namespace. A namespace isn't a type hence the error message. Is myClass actually a class? You defined Public Class myClass somewhere?
You are basically trying to do this: Dim x As New System.Windows.Forms What you wanted to do was: Dim x As New System.Windows.Forms.Form
Hope it helps some. Chris
"Geoff Jones" <no********@email.com> wrote in message news:41**********************@news.dial.pipex.com. .. Hi
I'm trying to use a class that I've written in a form. Unfortunately, when I write something like:
Public x As New myClass
I get the compile time error: "Type Expected". Indeed, the "squiggly" blue line does appear under myClass so I half expeced it. However, I had written
Imports myClass
in the form so I thought it would work.
Can anybody help? I'm obviously missing something obvious.
Geoff
Geoff, The class i.e. SmoothProgressBar, does not have a namespace explicitly in the code.
The class will implicitly have a namespace based on the project that you
create it in.
For example if you create a project called SmoothProgressBar, it will have a
root namespace of SmoothProgressBar, if you then create a class called
SmoothProgressBar in that project it will have a fully qualified name of
SmoothProgressBar.SmoothProgressBar.
Is SmoothProgressBar in the same project or a different project then the
form?
What is the name of the project SmoothProgressBar is in?
What is the name of the root namespace SmoothProgressBar is in?
You can use "Project - ... Properties - Common Properties - General - Root
namespace" to view & change the name of the root namespace for a project.
Hope this helps
Jay
"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ... Hi Jay
This is still puzzling me slightly - although the code is now working. The class i.e. SmoothProgressBar, does not have a namespace explicitly in the code. So, as I have already mentioned, I can only get the code to compile if I write
Dim x As New SmoothProgressBar.SmoothProgressBar
Is the namespace implicitly set to the name of the class?
I take your point about the namespace and the class name being the same - if only because it appears overkill and a lot of unnecessary typing. Interestingly enough, when I wrap the class in my own namespace e.g.
Namespace MyUtilityCollection
' The SmoothProgressBar class
End Namespace
I can call the tool by using
Dim x As New MyUtilityCollection.SmoothProgressBar
Which is less confusing!
Can anybody explain if the namespace is set implictly to the name of the class and if not why it appears to be happening in my application?
Thanks in advance
Geoff "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:uY**************@TK2MSFTNGP14.phx.gbl... Geoff, To avoid some subtle & potentially hard to follow ambiguity errors I avoid naming a namespace the same as a Class name.
Hope this helps Jay
<<snip>>
Hi Jay
Yes, the project has the name Smooth Progress Bar (note the spaces, but
maybe that doesn't make a difference in terms of namespace i.e. it will
still be SmoothProgressBar). It is in a different project to the main
application form.
This all makes sense now. Many thanks.
HAPPY NEW YEAR!!!!!
Geoff
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl... Geoff, The class i.e. SmoothProgressBar, does not have a namespace explicitly in the code. The class will implicitly have a namespace based on the project that you create it in.
For example if you create a project called SmoothProgressBar, it will have a root namespace of SmoothProgressBar, if you then create a class called SmoothProgressBar in that project it will have a fully qualified name of SmoothProgressBar.SmoothProgressBar.
Is SmoothProgressBar in the same project or a different project then the form?
What is the name of the project SmoothProgressBar is in?
What is the name of the root namespace SmoothProgressBar is in?
You can use "Project - ... Properties - Common Properties - General - Root namespace" to view & change the name of the root namespace for a project.
Hope this helps Jay
"Geoff Jones" <no********@email.com> wrote in message news:41***********************@news.dial.pipex.com ... Hi Jay
This is still puzzling me slightly - although the code is now working. The class i.e. SmoothProgressBar, does not have a namespace explicitly in the code. So, as I have already mentioned, I can only get the code to compile if I write
Dim x As New SmoothProgressBar.SmoothProgressBar
Is the namespace implicitly set to the name of the class?
I take your point about the namespace and the class name being the same - if only because it appears overkill and a lot of unnecessary typing. Interestingly enough, when I wrap the class in my own namespace e.g.
Namespace MyUtilityCollection
' The SmoothProgressBar class
End Namespace
I can call the tool by using
Dim x As New MyUtilityCollection.SmoothProgressBar
Which is less confusing!
Can anybody explain if the namespace is set implictly to the name of the class and if not why it appears to be happening in my application?
Thanks in advance
Geoff "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:uY**************@TK2MSFTNGP14.phx.gbl... Geoff, To avoid some subtle & potentially hard to follow ambiguity errors I avoid naming a namespace the same as a Class name.
Hope this helps Jay <<snip>>
Geoff,
As I stated you need to use "Project - ... Properties - Common Properties -
General - Root namespace" to see what the root namespace on your "Smooth
Progress Bar" project is. I would probably make the "Smooth Progress Bar"
namespace "myapp.controls" or "myapp.ui" where "myapp" is the root namespace
for the application itself. Remember that multiple projects can have the
same namespace...
I would have expected "Smooth_Progress_Bar", which is what I thought VS.NET
2003 does, however VS.NET 2002 & VS.NET 2005 may do something else, I almost
always change the root namespace, so I really don't remember the default...
Of course you can change either the root namespace or the project name after
the fact.
Hope this helps
Jay
"Geoff Jones" <no********@email.com> wrote in message
news:41***********************@news.dial.pipex.com ... Hi Jay
Yes, the project has the name Smooth Progress Bar (note the spaces, but maybe that doesn't make a difference in terms of namespace i.e. it will still be SmoothProgressBar). It is in a different project to the main application form.
This all makes sense now. Many thanks.
HAPPY NEW YEAR!!!!!
Geoff
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:OH**************@TK2MSFTNGP09.phx.gbl... Geoff, The class i.e. SmoothProgressBar, does not have a namespace explicitly in the code. The class will implicitly have a namespace based on the project that you create it in.
For example if you create a project called SmoothProgressBar, it will have a root namespace of SmoothProgressBar, if you then create a class called SmoothProgressBar in that project it will have a fully qualified name of SmoothProgressBar.SmoothProgressBar.
Is SmoothProgressBar in the same project or a different project then the form?
What is the name of the project SmoothProgressBar is in?
What is the name of the root namespace SmoothProgressBar is in?
You can use "Project - ... Properties - Common Properties - General - Root namespace" to view & change the name of the root namespace for a project.
Hope this helps Jay
"Geoff Jones" <no********@email.com> wrote in message news:41***********************@news.dial.pipex.com ... Hi Jay
This is still puzzling me slightly - although the code is now working. The class i.e. SmoothProgressBar, does not have a namespace explicitly in the code. So, as I have already mentioned, I can only get the code to compile if I write
Dim x As New SmoothProgressBar.SmoothProgressBar
Is the namespace implicitly set to the name of the class?
I take your point about the namespace and the class name being the same - if only because it appears overkill and a lot of unnecessary typing. Interestingly enough, when I wrap the class in my own namespace e.g.
Namespace MyUtilityCollection
' The SmoothProgressBar class
End Namespace
I can call the tool by using
Dim x As New MyUtilityCollection.SmoothProgressBar
Which is less confusing!
Can anybody explain if the namespace is set implictly to the name of the class and if not why it appears to be happening in my application?
Thanks in advance
Geoff "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:uY**************@TK2MSFTNGP14.phx.gbl... Geoff, To avoid some subtle & potentially hard to follow ambiguity errors I avoid naming a namespace the same as a Class name.
Hope this helps Jay <<snip>>
This discussion thread is closed Replies have been disabled for this discussion. Similar topics
5 posts
views
Thread by Rick |
last post: by
|
2 posts
views
Thread by Chuck Martin |
last post: by
|
1 post
views
Thread by The Late Nate the Great |
last post: by
|
4 posts
views
Thread by Daniel |
last post: by
|
3 posts
views
Thread by Jon |
last post: by
|
16 posts
views
Thread by Steve Chapel |
last post: by
|
2 posts
views
Thread by thj |
last post: by
| | | | | | | | | | | |