473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Q: "Type Expected"

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
Nov 21 '05 #1
14 14150
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

Nov 21 '05 #2
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


Nov 21 '05 #3
"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/>
Nov 21 '05 #4
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


Nov 21 '05 #5
Geoff,

Are you sure your class is public?

Cor
Nov 21 '05 #6
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

Nov 21 '05 #7
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

Nov 21 '05 #8
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


Nov 21 '05 #9
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



Nov 21 '05 #10
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


Nov 21 '05 #11
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



Nov 21 '05 #12
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>>
Nov 21 '05 #13
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>>

Nov 21 '05 #14
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>>


Nov 21 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rick | last post by:
I wrote the following code as part of a page where users can reorder a list of items by highlighting an item in a list box and clicking an "up" or "down" button to move the items around. The code...
2
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
1
by: The Late Nate the Great | last post by:
Using VC# in creating a .NET Compact Framework project, I received this message first thing Monday morning (talk about a bad omen for the week!). It gave a line number that didn't apply, and...
4
by: Daniel | last post by:
Hi, I have problem to get the control id and set its visible to true/false(mean show/hide). here is my code: <%@ Control Language="vb" AutoEventWireup="false" Codebehind="ucNavbar.ascx.vb"...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
16
by: Steve Chapel | last post by:
When I load the page <https://bugzilla.mozilla.org/attachment.cgi?id=237739with Internet Explorer 7 RC 1, I get the error "Object Expected" at line 174. When I click on the button, I also get the...
2
by: thj | last post by:
Hi. I've got this form that I'm trying to validate: <form id="periodForm" action="" method="post"> <p> Periode: <input id="startDate" name="startDate" type="text" size="7" value="<%=...
4
by: makweatan | last post by:
Hello, Can anyone please help me, where did I go wrong..? Line : 388 Char : 1 Error : Object Expected Code : 0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.