Name 'x' is not declared question

P

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
 
P

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

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
 
P

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

;-)
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

pb said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top