473,795 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Name 'x' is not declared question

pb
Hi,

I have built a page with some generic functions in the code behind -
all works fine.

I then wanted to put these functions in their own code modules, so in
the app_code folder I created class1.vb with the content such as...

------------------------------------------------
Imports Microsoft.Visua lBasic

Public Class Class1

Public Function xx() As Boolean
xx = True
End Function

End Class
----------------------------------------

Now in the code behind page, from where this function is called, I get
the error message "name 'xx' is not declared"

I've read the documentation as far as I can fugure out, this should
work. I would sure appreciate if anyone can tell me what I am missing.

Thanks,

Pb

Jun 4 '07 #1
3 2080
pb
On Jun 5, 8:53 am, pb <philbrier...@h otmail.comwrote :
Hi,

I have built a page with some generic functions in the code behind -
all works fine.

I then wanted to put these functions in their own code modules, so in
the app_code folder I created class1.vb with the content such as...

------------------------------------------------
Imports Microsoft.Visua lBasic

Public Class Class1

Public Function xx() As Boolean
xx = True
End Function

End Class
----------------------------------------

Now in the code behind page, from where this function is called, I get
the error message "name 'xx' is not declared"

I've read the documentation as far as I can fugure out, this should
work. I would sure appreciate if anyone can tell me what I am missing.

Thanks,

Pb
I've figured out that if I change the inherits bit at the top of the
code behind page it now sees the function, but a load of other errors
now occur. How do I make class1 visible to system.web.UI.P age?

'Inherits System.Web.UI.P age
Inherits class1

Jun 4 '07 #2
pb
On Jun 5, 9:15 am, pb <philbrier...@h otmail.comwrote :
On Jun 5, 8:53 am, pb <philbrier...@h otmail.comwrote :


Hi,
I have built a page with some generic functions in the code behind -
all works fine.
I then wanted to put these functions in their own code modules, so in
the app_code folder I created class1.vb with the content such as...
------------------------------------------------
Imports Microsoft.Visua lBasic
Public Class Class1
Public Function xx() As Boolean
xx = True
End Function
End Class
----------------------------------------
Now in the code behind page, from where this function is called, I get
the error message "name 'xx' is not declared"
I've read the documentation as far as I can fugure out, this should
work. I would sure appreciate if anyone can tell me what I am missing.
Thanks,
Pb

I've figured out that if I change the inherits bit at the top of the
code behind page it now sees the function, but a load of other errors
now occur. How do I make class1 visible to system.web.UI.P age?

'Inherits System.Web.UI.P age
Inherits class1- Hide quoted text -

- Show quoted text -
OK - figured it out. Trawling this group came up with a lot of people
asking the same question but few simple answers, so here it is...

In code behind file you have to put

Dim MyCommonFunctio ns As New class1
and the use like

y = MyCommonFunctio ns.xx

;-)

Jun 5 '07 #3
pb wrote:
On Jun 5, 9:15 am, pb <philbrier...@h otmail.comwrote :
>On Jun 5, 8:53 am, pb <philbrier...@h otmail.comwrote :


>>Hi,
I have built a page with some generic functions in the code behind -
all works fine.
I then wanted to put these functions in their own code modules, so in
the app_code folder I created class1.vb with the content such as...
------------------------------------------------
Imports Microsoft.Visua lBasic
Public Class Class1
Public Function xx() As Boolean
xx = True
End Function
End Class
----------------------------------------
Now in the code behind page, from where this function is called, I get
the error message "name 'xx' is not declared"
I've read the documentation as far as I can fugure out, this should
work. I would sure appreciate if anyone can tell me what I am missing.
Thanks,
Pb
I've figured out that if I change the inherits bit at the top of the
code behind page it now sees the function, but a load of other errors
now occur. How do I make class1 visible to system.web.UI.P age?

'Inherits System.Web.UI.P age
Inherits class1- Hide quoted text -

- Show quoted text -

OK - figured it out. Trawling this group came up with a lot of people
asking the same question but few simple answers, so here it is...

In code behind file you have to put

Dim MyCommonFunctio ns As New class1
and the use like

y = MyCommonFunctio ns.xx

;-)
If your method doesn't use any data from it's class, you should make it
static (Shared in VB):

Public Shared Function xx() As Boolean
xx = True
End Function

For static methods you don't need to create an instance of the class to
use them, just specify the class name and the method name:

y = Class1.xx

--
Göran Andersson
_____
http://www.guffa.com
Jun 5 '07 #4

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

Similar topics

4
2248
by: Dan Jacobson | last post by:
Using <A name="x_y-z"></A>, I even get nervous about the _ and -. w3-recs/RECS/html4/struct/links.html seems to say all of ascii is cool and beyond. Anyway, just what is the safe range for characters in a name="" ? I don't plan to go beyond usual Unix filename chars.
8
19603
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
13
12393
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
3
2006
by: marylipscomb | last post by:
I have a question about my asp.net application. It tells me that Name 'lblMessage' is not declared. Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30451: Name 'lblMessage' is not declared. Source Error:
4
2723
by: andrew | last post by:
Hi, I have routinely added anchors to pages using both name and id: <a name="example" id="example"></a> under the possibly mistaken assumption that at some stage "name" might be deprecated but "id" was unlikely to be. Can I ask what is accepted practice currently?
6
4432
by: rdstevenson | last post by:
Hi, Something I've never come across before and has given me a headache. I have a txt file with content similar to below I want to read in each line do a split on the = and then create a variable with the name of the first value and the value of the second. I'm fine with the splitting etc but I haven't got a clue of how to set the variable name to the value on another variable? any ideas anyone?
15
1865
by: TonyV | last post by:
Hey all, for debugging purposes, I'd like to be able to access an object's instance name from within the object class. For example, I'd like to be able to do something like this: ------------------------------------------------------------ function FooClass() { // definition of FooClass members } FooClass.prototype.Debug = function() {
2
4857
by: developer.new | last post by:
Hi I have a question regarding this concept I learned about recently: Name Hiding. Here's what I've come across: There is a base class with two functions with the same name but different signature. A class inherits publicly from this base class and redefines one of the two functions in the derived class. In that case, a derived class object cannot access the other base class function that it hasn't redefined. I'm posting a code snippet...
0
1224
by: padmagvs | last post by:
I have a wsdl something like this <?xml version="1.0" ?> <definitions targetNamespace="http://abc.com/namespace/wsif/samples/abc" xmlns:tns="http://abc.com/namespace/wsif/samples/abc" xmlns:typens="urn:xml-soap-address-demo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
0
9673
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
9522
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,...
1
10167
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,...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
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();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.