Welcome to Dream.In.Code
Become a VB Expert!

Join 150,138 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,252 people online right now. Registration is fast and FREE... Join Now!




functions

 
Reply to this topicStart new topic

functions, asap

jencalma
12 Jul, 2008 - 02:51 AM
Post #1

D.I.C Head
**

Joined: 13 Jul, 2007
Posts: 62


My Contributions
i'm confused on how to return the value in user defined functions,, please take a look to the functions that i'm working on and please tell what is the problem,,

vb
Private Sub cmdcompute_Click()
Dim preleccs%, midleccs%, finleccs%, sum%

preleccs = Val(txtpreleccs.Text)
midleccs = Val(txtmidleccs.Text)
finleccs = Val(txtfinleccs.Text)

classlec = sum(preleccs, midleccs, finleccs)
lblcslec = FormatNumber(Val(classlec * 0.7))
End Sub

Private sum(plecs%, mlecs%, flecs%) As Integer
sum = (((prelcs + midlecs + flecs) / 300) * 100)
End Sub



thanks for the help,, smile.gif
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Functions
12 Jul, 2008 - 03:03 AM
Post #2

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,032



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Unlike other languages such as C/C++, Java etc. VB differentiates between functions that return values and functions that do not.

Functions in VB are procedures which return a value while Subroutines are procedures that do not return a value.

To use a user-defined function that returns a value, you will need to use this code construct:
vb

[Private/Public] Function <FunctionName>([parameterList]) As [ReturnType]
' function code goes here
FunctionName = <return Value>
End Function


For example, to write a function that returns a square of a number,
vb

Private Function SquareN(ByVal n as Integer) As Integer
SquareN = n * n
End Function


Hope this helps.
smile.gif
User is offlineProfile CardPM
+Quote Post

jencalma
RE: Functions
12 Jul, 2008 - 03:09 AM
Post #3

D.I.C Head
**

Joined: 13 Jul, 2007
Posts: 62


My Contributions
QUOTE(born2c0de @ 12 Jul, 2008 - 04:03 AM) *

Unlike other languages such as C/C++, Java etc. VB differentiates between functions that return values and functions that do not.

Functions in VB are procedures which return a value while Subroutines are procedures that do not return a value.

To use a user-defined function that returns a value, you will need to use this code construct:
vb

[Private/Public] Function <FunctionName>([parameterList]) As [ReturnType]
' function code goes here
FunctionName = <return Value>
End Function


For example, to write a function that returns a square of a number,
vb

Private Function SquareN(ByVal n as Integer) As Integer
SquareN = n * n
End Function


Hope this helps.
smile.gif


thanks for the help,, smile.gif

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:04AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month