473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem with module

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é

Mar 16 '07 #1
4 1007
André wrote:
<snip>
Sub Main()
MyFunction()
End Sub
<snip>
Label1.Text = Mymodule.Main
<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.

Mar 16 '07 #2
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.tyschreef in bericht
news:uO****************@TK2MSFTNGP03.phx.gbl...
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é

Mar 16 '07 #3
André wrote:
<snip>
So, the Sub Main() is completely useless?
Nope. I mean, it *is not* useless.

See, Subs, in general, are methods that do things, from which you
don't expect a result. Functions, on the other side, usually calculate
things and return a result, although most languages (including VB)
allow you to implicitly discard the Function's result and call the
Function as if it was a Sub -- for what we call "the function's side-
effects" (notice, however, that a Sub *can't* be used as a Function.
Could you guess why?). Properties allow you access to the internal
state of an object. A Property is like the mixing of a Sub to *set*
the value with a function to *get* it back (that's why properties are
usually called, in some languages, getters and setters).

Now, Sub Main has, for historical reasons, the job of marking the
entry point of the "application". It's the first method to be called
by the framework when it is about to execute your code.

To be used like this, the Sub Main has to be a Shared method in a
class, or it must be declared in a Module. And, of course, you must
indicate to the compiler which Sub Main is *the* main sub (usually in
the application properties, if you're using the MS IDEs).
And is it possible to put the code in code-behind, or it must be put, like a
class, in a .vb file?
<snip>

Unfortunately I have no idea of what you're asking. Maybe you can
state your question more clearly...

HTH.

regards,

Branco.
Mar 17 '07 #4
Thanks again,

I suppressed the Main() sub and it works.
I don't know whether it's relevant, but i use VB.net in the ASP.Net context,
so i don't think that Sub Main() is relevant here .... I remember that is
was indeed used in VB language.

About putting the code in code-behind or in a .vb file question, again it's
related to ASP.Net where all files containing classes must be placed in
subdir APP_Code. Code-behind is the VB.Net part of an aspx file ...


"Branco Medeiros" <br*************@gmail.comschreef in bericht
news:11**********************@e65g2000hsc.googlegr oups.com...
André wrote:
<snip>
So, the Sub Main() is completely useless?
Nope. I mean, it *is not* useless.

See, Subs, in general, are methods that do things, from which you
don't expect a result. Functions, on the other side, usually calculate
things and return a result, although most languages (including VB)
allow you to implicitly discard the Function's result and call the
Function as if it was a Sub -- for what we call "the function's side-
effects" (notice, however, that a Sub *can't* be used as a Function.
Could you guess why?). Properties allow you access to the internal
state of an object. A Property is like the mixing of a Sub to *set*
the value with a function to *get* it back (that's why properties are
usually called, in some languages, getters and setters).

Now, Sub Main has, for historical reasons, the job of marking the
entry point of the "application". It's the first method to be called
by the framework when it is about to execute your code.

To be used like this, the Sub Main has to be a Shared method in a
class, or it must be declared in a Module. And, of course, you must
indicate to the compiler which Sub Main is *the* main sub (usually in
the application properties, if you're using the MS IDEs).
And is it possible to put the code in code-behind, or it must be put, like
a
class, in a .vb file?
<snip>

Unfortunately I have no idea of what you're asking. Maybe you can
state your question more clearly...

HTH.

regards,

Branco.
"Branco Medeiros" <br*************@gmail.comschreef in bericht
news:11**********************@e65g2000hsc.googlegr oups.com...
André wrote:
<snip>
So, the Sub Main() is completely useless?
Nope. I mean, it *is not* useless.

See, Subs, in general, are methods that do things, from which you
don't expect a result. Functions, on the other side, usually calculate
things and return a result, although most languages (including VB)
allow you to implicitly discard the Function's result and call the
Function as if it was a Sub -- for what we call "the function's side-
effects" (notice, however, that a Sub *can't* be used as a Function.
Could you guess why?). Properties allow you access to the internal
state of an object. A Property is like the mixing of a Sub to *set*
the value with a function to *get* it back (that's why properties are
usually called, in some languages, getters and setters).

Now, Sub Main has, for historical reasons, the job of marking the
entry point of the "application". It's the first method to be called
by the framework when it is about to execute your code.

To be used like this, the Sub Main has to be a Shared method in a
class, or it must be declared in a Module. And, of course, you must
indicate to the compiler which Sub Main is *the* main sub (usually in
the application properties, if you're using the MS IDEs).
And is it possible to put the code in code-behind, or it must be put, like
a
class, in a .vb file?
<snip>

Unfortunately I have no idea of what you're asking. Maybe you can
state your question more clearly...

HTH.

regards,

Branco.

Mar 17 '07 #5

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

Similar topics

0
by: alejandro david weil | last post by:
Hello! I got the next problem and didn't see any reference to the behaviour that produces it, look: If we have a module like: --- mod.py --------------->8------ testvar2 = 15
0
by: John Roth | last post by:
I've found a case where it seems that Python is importing two copies of a module without any reason or indication. It took me a while to verify that this is what is occuring: I had to write a...
2
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the...
25
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30...
8
by: Nadav | last post by:
Hi, Introduction: ********************* I am writing a mixed mode application I have a COM module and a .NET module that communicate with each other. The COM exposes a custom sink interface,...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
3
by: Mohamed Yousef | last post by:
Hello , The problem I'm asking about is how can imported modules be aware of other imported modules so they don't have to re-import them (avoiding importing problems and Consicing code and...
13
by: Rafe | last post by:
Hi, I am in a situation where I feel I am being forced to abandon a clean module structure in favor of a large single module. If anyone can save my sanity here I would be forever grateful. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.