Question:
How do I write Functions in Microsoft Visual Basic?
Answerz
2007-02-10 19:44:53 UTC
I am having the hardest time writing functions in visual basic. I understand that they DON'T return values as is; but the setting or parameters and ByVal have made me more confused. If possible, please, give an example of some sort.
Three answers:
2007-02-10 22:26:15 UTC
Functions in VB return values !!

Sintaxis:



Function ( )

=

End Function





Examples:



Function AddValue(Num1 As Integer, num2 As Integer) As Integer

Dim nTot As Integer



nTot = Num1 + num2

AddValue = nTot

End Function



Function AddString(Str1 As String, Str2 As String) As String

AddString = Str1 & Str2

End Function





AddValue() function Acept 2 Integers types parameters "(Num1 As Integer, num2 As Integer)"

AddValue() function Return a Value of Integer type. "As Integer"

(To return a value, just assign the value to return to the function name " AddValue = nTot")





AddString() function Acept 2 Strings types parameters "(Str1 As String, Str2 As String)"

AddString() function Return a Value of String type. "As String"

(To return a value, just assign the value to return to the function name " AddString = Str1 & Str2")
2007-02-10 20:00:32 UTC
MSDN has some examples ... Give them a try.



Functions *can* and *do* return values - after all,

that is what a function actually does, process an

input to give you an output, i.e.



Function: Input Value ==> process ==> Output



Try not to confuse Functions with Subroutines.





HTH
?
2016-11-03 07:01:47 UTC
on your excelsheet, go with the cellular you like the consequence in. After doing this, hint your mouse to the long bar on suitable of the sheet, that feels like an address bar. There you will see an illustration that resembles an 'fx'. click on it, go with your needed function, go with your cells and you're waiting to circulate! take excitement in!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...