473,406 Members | 2,217 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,406 software developers and data experts.

function with no return value works without problem

arunmib
104 100+
Hi all,
Before posting my question I would like to state that "I am novice in VB, rather to say I am learning VB. My previous coding experience has been with C/C++". Ok, now to the question.

Expand|Select|Wrap|Line Numbers
  1. Public Function Add(ByVal iNum1 as Integer, ByVal iNum2 as Integer) As Integer
  2.  
  3. Dim iSum as Integer = 0
  4.  
  5. iSum = iNum1 + iNum2
  6.  
  7. End Sub
So, conceptually speaking there is no "return" statement in the function. So when I build my project there must be an error right. But everything builds fine, not even a warning and I am even able to run the code without any problem and i get the expected(correct) answer.

I mean how is this possible????


P.S : I am using VB.Net and tool is Visual Studio 2003.
Sep 20 '07 #1
5 5867
kadghar
1,295 Expert 1GB
Hi all,

I mean how is this possible????


P.S : I am using VB.Net and tool is Visual Studio 2003.
well that's possible, if you move variables that aren't byval or private inside a function, they'll change in the whole program.

the problem of not giving a return value is that you wont be able to do something like this:

a = sum(b)

you'll have to call the function as a procedure... and in that case, its better to create a procedure (sub) and call it.

In latter versions of VB (like vb express edition) you'll recieve a warning if you do this.
Sep 20 '07 #2
Killer42
8,435 Expert 8TB
I don't see anything wrong with the posted code, except that...
  • Since you don't set the return value, I would expect it to always return 0
  • End Sub isn't correct for a function, but perhaps VB2003 has a more relaxed attitude to that than VB6.

Is it possible that you are actually invoking a built-in Add function rather than your own code?
Sep 21 '07 #3
QVeen72
1,445 Expert 1GB
... So, conceptually speaking there is no "return" statement ...
Hi,

In VB6 and higher versions (.Net), you don't have to specify "Return" keyword (like you do in C++).
Yes, It dosen't throw any error.
In the above Function, Function Name should be populated with the Result (which has to be returned)

Add = iSum

In calling program, you can specify

txtSum.Text = Add(2, 8)


Regards
Veena
Sep 21 '07 #4
Killer42
8,435 Expert 8TB
... In VB6 and higher versions (.Net), you don't have to specify "Return" keyword (like you do in C++).
Just a historical note; there was no Return available in any of the VB versions up to and including version 6.



(Well... technically there is a Return statement, but it has a completely different meaning and should be ignored here.)
Sep 21 '07 #5
arunmib
104 100+
thanks for the reply ppl :-)
Sep 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24...
35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
6
by: lovecreatesbeauty | last post by:
I ever missed a `return' statement when write a function `int HighDigit(Num)' to get the highest digit of an integer. But even if the `return' statement is ignored the function still can obtain...
2
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
6
by: ais523 | last post by:
I'm trying to write a function that does some realloc-style modification of a pointer. The function itself works, but I'm having some problems with the prototype. This is a simple example of the...
18
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is...
2
by: paolo | last post by:
Thanks in advance to everyone that will give me help for these questions. The function formatCurrency is used to auto-format a numeric value with thousands separators and a decimal separator. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.