VB NOTES PART 8

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

Info iconThis 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 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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 dont 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

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online