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

Home Posts Topics Members FAQ

Function return question.

I am curious as to why ASP.NET returns values a different way from VB or
VB.net (or can you use both).

In my one book I have it returning using a return statement

*************** *************** *************** **************
function RollDie As Integer
Dim Roll As Integer
Randomize
Roll = Int(rnd * 6) + 1
Return(roll)
end function
*************** *************** *************** **************

instead of return it only with the assigment to the function name:

*************** *************** *************** **************
function RollDie As Integer
Dim Roll As Integer
Randomize
Roll = Int(rnd * 6) + 1
end function
*************** *************** *************** ***************

Are both of these correct?

Thanks,

Tom.

Nov 18 '05 #1
3 1808
Thomas Scheiderich <tf*@deltanet.c om> wrote in news:4031325E.5 040509
@deltanet.com:
I am curious as to why ASP.NET returns values a different way from VB or
VB.net (or can you use both).

In my one book I have it returning using a return statement

*************** *************** *************** **************
function RollDie As Integer
Dim Roll As Integer
Randomize
Roll = Int(rnd * 6) + 1
Return(roll)
end function
*************** *************** *************** **************

instead of return it only with the assigment to the function name:

*************** *************** *************** **************
function RollDie As Integer
Dim Roll As Integer
Randomize
Roll = Int(rnd * 6) + 1
end function
*************** *************** *************** ***************

Are both of these correct?


Assuming the second one is RollDie instead of Roll, they are just alternate
syntaxes AFAIK.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 18 '05 #2
The VB 6.0 way was to assign the function name to a value. In .NET, you
use: "Return someValue".

So,

Return Roll

....and...

RollDie = Roll

would return the same value (in your second example you didn't set the
function equal to anything, so you would get any value from your second
version).

The difference between the two is that "Return" not only set the value of
the function, but it also exits from the function after it executes, so any
code written after Return will not run, whereas by setting the return value
= to something where all the code will run up to the End Function statement.

For example:

Function RollDie As Integer
Dim Roll As Integer
Dim y as new Random
Roll = y.next(1,6)
Return Roll
'This next line will never execute because the function will "Return"
control back to the calling procedure after the above line.
Dim x as String = "Test"
End Function

Also note the use of the new .NET Random class and its next method as
opposed to the VB 6 Randomize() and Rnd() functions.

"Thomas Scheiderich" <tf*@deltanet.c om> wrote in message
news:40******** ******@deltanet .com...
I am curious as to why ASP.NET returns values a different way from VB or
VB.net (or can you use both).

In my one book I have it returning using a return statement

*************** *************** *************** **************
function RollDie As Integer
Dim Roll As Integer
Randomize
Roll = Int(rnd * 6) + 1
Return(roll)
end function
*************** *************** *************** **************

instead of return it only with the assigment to the function name:

*************** *************** *************** **************
function RollDie As Integer
Dim Roll As Integer
Randomize
Roll = Int(rnd * 6) + 1
end function
*************** *************** *************** ***************

Are both of these correct?

Thanks,

Tom.

Nov 18 '05 #3
Scott M. wrote:
The VB 6.0 way was to assign the function name to a value. In .NET, you
use: "Return someValue".

So,

Return Roll

...and...

RollDie = Roll

would return the same value (in your second example you didn't set the
function equal to anything, so you would get any value from your second
version).

The difference between the two is that "Return" not only set the value of
the function, but it also exits from the function after it executes, so any
code written after Return will not run, whereas by setting the return value
= to something where all the code will run up to the End Function statement.

For example:

Function RollDie As Integer
Dim Roll As Integer
Dim y as new Random
Roll = y.next(1,6)
Return Roll
'This next line will never execute because the function will "Return"
control back to the calling procedure after the above line.
Dim x as String = "Test"
End Function
My mistake here as the line should be:

RollDie = Int(rnd * 6) + 1
Which does work.

Also note the use of the new .NET Random class and its next method as
opposed to the VB 6 Randomize() and Rnd() functions.


I'll definately need to look into these.

Thanks,

Tom.


"Thomas Scheiderich" <tf*@deltanet.c om> wrote in message
news:40******** ******@deltanet .com...
I am curious as to why ASP.NET returns values a different way from VB or
VB.net (or can you use both).

In my one book I have it returning using a return statement

************* *************** *************** *************** *
function RollDie As Integer
Dim Roll As Integer
Randomize
Roll = Int(rnd * 6) + 1
Return(roll )
end function
************* *************** *************** *************** *

instead of return it only with the assigment to the function name:

************* *************** *************** *************** *
function RollDie As Integer
Dim Roll As Integer
Randomize
Roll = Int(rnd * 6) + 1
end function
************* *************** *************** *************** **

Are both of these correct?

Thanks,

Tom.



Nov 18 '05 #4

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

Similar topics

21
3860
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am writing something up on functions, and I don't like writing about things I am not sure about. Ok, then, here we go: I initially thought that one would only really need to use a function
4
3631
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's useful to help me to solve some basic problem which I may not perceive before. I appreciate your help, sincerely.
5
1776
by: D. Shane Fowlkes | last post by:
This may be a very basic question but it's something I've never done before. I've looked at a couple of my favorite sites and books and can't find an answer either. I can write a Function to return a single value. No big deal. But I want to call a Function from another Sub and the function finds and returns an entire db record. Using ASP.NET (VB!), how can this be done and how can I differentiate between the fields/columns? For...
14
1848
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ????? OK, this function may return a boolean, and if this is true, then no message back is really required, but if it fails then some supporting message needs to be returned to the calling code. As I see it there are a few options.
7
1879
by: Csaba Gabor | last post by:
I feel like it's the twilight zone here as several seemingly trivial questions are bugging me. The first of the following three lines is a syntax error, while the last one is the only one that shows the alert. What is the essential reason? function () { alert('hi mom'); }(); function () { alert('hi dad'); }(8); var x=function () { alert('hi bro'); }();
3
3658
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
32
3349
by: chris.fairles | last post by:
Just want an opinion. I have an algorithm that needs to run as fast as possible, in fact. Its already too slow. I've done as much algorithmic changes as I can to reduce the amount of code, so now I'm turning to micro-optimizations. One function that gets run a bazillion times is the pow() function from math.h. However I've realized probably 90% of the time, the exponent will be 0. 99.9% of the time, the exponent will lie between -3 and...
2
1924
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function The question may be silly or even meaning less but please............
14
562
by: Pramod | last post by:
I have one question. Can I catch exception in function overloading.In my programm i want to create two function with same signature and same return type. I know its not possible...can i use try.catch .block to hand this exception.
12
4655
by: Googy | last post by:
Hi!! Can any one explain me the meaning of following notations clearly : 1. typedef char(*(*frpapfrc()))(); frpapfrc f; 2. typedef int (*(arr2d_ptr)()); arr2d_ptr p; 3. typedef int (*(*(*ptr2d_fptr)()))();
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,...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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.