By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Name 'x' is not declared question

P: n/a
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.VisualBasic

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
Share this Question
Share on Google+
3 Replies


P: n/a
pb
On Jun 5, 8:53 am, pb <philbrier...@hotmail.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.VisualBasic

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.Page?

'Inherits System.Web.UI.Page
Inherits class1

Jun 4 '07 #2

P: n/a
pb
On Jun 5, 9:15 am, pb <philbrier...@hotmail.comwrote:
On Jun 5, 8:53 am, pb <philbrier...@hotmail.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.VisualBasic
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.Page?

'Inherits System.Web.UI.Page
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 MyCommonFunctions As New class1
and the use like

y = MyCommonFunctions.xx

;-)

Jun 5 '07 #3

P: n/a
pb wrote:
On Jun 5, 9:15 am, pb <philbrier...@hotmail.comwrote:
>On Jun 5, 8:53 am, pb <philbrier...@hotmail.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.VisualBasic
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.Page?

'Inherits System.Web.UI.Page
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 MyCommonFunctions As New class1
and the use like

y = MyCommonFunctions.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 discussion thread is closed

Replies have been disabled for this discussion.