Groups | Blog | Home
all groups > asp.net > march 2007 >

asp.net : problem with module


Branco Medeiros
3/16/2007 2:03:44 PM
[quoted text, click to view]
<snip>

You can't assign the result of a Sub to anything, because a Sub
doesn't return values. Only functions and properties do. Thus the
compilation error.

(in the case of your call to MyFunction inside Main, its returned
value is silently discarded)

HTH.

Regards,

Branco.
André
3/16/2007 8:16:11 PM
Hi,

I wrote this module in file "module.vb" and put it in App_Code of my asp.net
application.

Imports Microsoft.VisualBasic
Public Module Mymodule
Sub Main()
MyFunction()
End Sub

Function MyFunction()
Return "function in module"
End Function
End Module

From code-behind, i do:
----------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Label1.Text = Mymodule.MyFunction
Label1.Text = Mymodule.Main
End Sub

The first line gives the correct output, but the second line produces error
"Expression does not produce a value."

I thought: sub Main() starts function Myfunction which renders the string
"function in module" ...
By the way, is it possible to place the module in code-behind?

Thanks for help
André


André
3/16/2007 11:50:18 PM
Hi, thanks for replying.
So, the Sub Main() is completely useless?
And is it possible to put the code in code-behind, or it must be put, like a
class, in a .vb file?

Thanks again

"André" <an@dre.ty> schreef in bericht
news:uOxBS%23$ZHHA.3996@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button