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. - Public Function Add(ByVal iNum1 as Integer, ByVal iNum2 as Integer) As Integer
-
-
Dim iSum as Integer = 0
-
-
iSum = iNum1 + iNum2
-
-
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.
5 5867
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.
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?
... 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
... 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.)
thanks for the reply ppl :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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) {...
|
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. ...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |