{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

VB NOTES PART 8 - Function Square(ByVal input As Double As...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
2/22 ------Two big ideas Code re-use Save time & effort by using code you or someone else previously developed Divide & conquer Solution to a larger problem can often be decomposed into solutions for several sub-problems ----remember: objects have properties and methods Methods in VB are implemented using procedures Two types of procedures : Functions small piece of code that I can call(execute) when needed Subroutines when calling a function you may need to pass it parameters ----We have already seen some functions in Foundation Class Library (FCL) Val (X ) string Pmt (interest, numPayments, principal) Returns loan payment Str (X) String. Format (formatString, the String) Math. Max (X,Y)----------choose the larger one from X and Y Math.Sqrt(X)---------------square root of X
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Function Square (ByVal input As Double ) As Double Name parameter list return type (Function will “return” a Double) ByVal means “sending a copy” parameter type Return input * input End Function Elsewhere in code (anywhere in class) Dim x As Double = 5.0 Dim y As Double Y = Square (x)-------procedure call execution is transferred to body of function, then jumps back Y gets return value One argument for each parameter Function Divide (ByVal x As Double, ByVal y As Double) As Double Return x/y End Function-------Subroutines (Sub) work like functions but don’t return a value All of the event handlers are subroutines When do I need subroutine? • code is too long • processing done more than once---procedure should have one clearly-defined task...
View Full Document

{[ snackBarMessage ]}