472,811 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1753
Thomas Scheiderich <tf*@deltanet.com> wrote in news:4031325E.5040509
@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/
"Programming 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.com> 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.com> 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
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...
4
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...
5
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...
14
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 ?????...
7
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...
3
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'...
32
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...
2
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 ...
14
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...
12
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...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.