473,883 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14206
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********@ema il.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:

SmoothProgressB ar

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******** ******@TK2MSFTN GP14.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********@ema il.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********@ema il.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******** ******@TK2MSFTN GP14.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********@ema il.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********@ema il.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******** ********@TK2MSF TNGP09.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 SmoothProgressB ar.SmoothProgre ssBar

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******** ******@TK2MSFTN GP15.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********@ema il.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********@ema il.com> wrote in message
news:41******** *************** @news.dial.pipe x.com...
As per the posts above, I've solved it by writing:

Public x As New SmoothProgressB ar.SmoothProgre ssBar

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******** ******@TK2MSFTN GP15.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********@ema il.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

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

Similar topics

5
2728
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 below is for the up and down buttons along with a reset button (which reloads the list as it was originally) and a change button which applies the changes. In Explorer and Safari for Mac, this code works flawlessly. When I tested on Explorer in...
2
9809
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 in a link. that function can have parameters for URL and window name passed to it. This works peachy in Firefox (1.0). With IE 6 (6.0.29) on two separate computers, I get an "onject expected" error. Going to the MS-based debugger just tells me...
1
4657
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 double-clicking on the error did nothing. Knowing how many problems there have been in Microsnot's tools throughout this project, I tried simply closing VisStudio and reopening the project. The error mysteriously vanished.
4
2225
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" Inherits="UserInterfaceDesign.ucNavbar" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> <A id="hpL" href="" DESIGNTIMEDRAGDROP="59" runat="server"
3
3199
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 missing from the code? Thanks - Jon Private Sub MakeParentTable() ' Create a new DataTable. Dim myDataTable As Datatable = New Datatable("ParentTable")
16
47712
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 same error on line 186. This same HTML and JavaScript works perfectly in Firefox and Opera. How can I make the code work in IE?
2
5748
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="<%= ViewData %>" /> -
4
2067
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
9940
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11142
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10415
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9574
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7128
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4220
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.