[ Pobierz całość w formacie PDF ]
.For a description of the function s arguments, see the IPmt() entry.Notice that the Pmt() functiondoesn t require the per argument because all payments are equal.The code for calculating the monthly payment is similar to the code examples in the IPmt() andPPmt() entries.FV(rate, nper, pmt[, pv[, type]])This function returns the future value of a loan based on periodic, fixed payments and a fixed inter-est rate.The arguments of the FV() function are explained in the IPmt() entry, and the pmt argumentis the payment made in each period.Suppose you want to calculate the future value of an investment with an interest rate of 6.25%,48 monthly payments of $180, and a present value of $12,000.Use the FV() function with the fol-lowing arguments:Dim PVal, FVal As IntegerDim APR, Payment As DoubleDim TotPmts As IntegerPayment = 180APR = 6.25 / 100TotPmts = 48PVal = 12000FVal = FV(APR / 12, TotPmts, -Payment, -PVal, DueDate.BegOfPeriod)MsgBox( After & TotPmts & months your savings will be worth $ & FVal)The actual result is close to $25,000.NPer(rate, pmt, pv[, fv[, type]])This function returns the number of periods for a loan based on periodic, fixed payments and afixed interest rate.For a description of the function s arguments, see the IPmt() entry.Suppose you borrow $25,000 at 11.5%, and you can afford to pay $450 per month.To figureout what this means to your financial state in the future, you would like to know how may years itwill take you to pay off the loan.Here s how you can use the NPer() function to do so:Dim PVal, FVal As IntegerDim APR, Payment As DoubleFILE I/O chF39Dim TotPmts As IntegerFVal = 0PVal = 25000APR = 0.115 / 12Payment = 450TotPmts = NPer(APR, -Payment, PVal, FVal, DueDate.EndOfPeriod)If Int(TotPmts) TotPmts Then TotPmts = Int(TotPmts) + 1Console.WriteLine( The loan s duration will be: & TotPmts & months )The actual duration of this loan is 80 months, which corresponds to nearly 6.5 years.If the pay-ment is increased from $450 to $500, the loan s duration will drop to 69 months, and a monthlypayment of $550 will bring the loan s duration down to 60 months.Rate(nper, pmt, pv[, fv[, type[, guess]]])You use this function to figure out the interest rate per payment period for a loan.Its arguments arethe same as with the preceding financial functions, except for the guess argument, which is the esti-mated interested rate.If you omit the guess argument, the value 0.1 (10%) is assumed.Table 18 lists and describes the remaining financial functions.All return values are Doubles.Table 18: Additional Financial FunctionsFunction ReturnsPV() The present value of an investmentNPV() The net present value of an investment based on a series of periodic cash flows and adiscount rateIRR() The internal rate of return for an investmentMIRR() The modified internal rate of return for a series of periodic cash flowsDDB() The depreciation of an asset for a specific time period using the double-declining balancemethod or some other method you specifySYD() The sum-of-years digits depreciation of an asset for a specified periodSLN() The straight-line depreciation of an asset for a single periodFile I/OAn important aspect of any programming other language, is its ability to access and manipulate files.Visual Basic supports three types of files:Æ% SequentialÆ% Random-access filesÆ% Binary fileschF40 BONUS REFERENCE VB.NET FUNCTIONS AND STATEMENTSSequential files are mostly text files (the ones you can open with a text editor such as Notepad).These files store information as it s entered, one byte per character.Even the numbers in a sequen-tial file are stored as string and not as numeric values (that is, the numeric value 33.4 is not storedas a Single or Double value, but as the string 33.4 ).These files are commonly created by text-processing applications and are used for storing mostly text, not numbers.Sequential files are read from the beginning to the end.Therefore, you can t read and write at thesame time to a sequential file.If you must read from and write to the file simultaneously, you mustopen two sequential files, one for reading from and another one for writing to.If your application requires frequent access to the file s data (as opposed to reading all the datainto memory and saving them back when it s done), you should use random-access files.Like thesequential files, random-access files store text as characters, one byte per character.Numbers, how-ever, are stored in their native format (as Integers, Doubles, Singles, and so on).You can display arandom-access file in a DOS window with the TYPE command and see the text, but you won t beable to read the numbers.Random-access files are used for storing data that are organized in segments of equal length.These segments are called records.Random-access files allow you to move to any record, as long asyou know where the desired record is located.Since all records have the same length, it s easy tolocate any record in the file by its index.Moreover, unlike sequential files, random-access files can beopened for reading and writing at the same time.If you decide to change a specific record, you canwrite the new record s data on top of the old record, without affecting the adjacent records.Binary files, finally, are similar to sequential files, and they make no assumption as to the type ofdata stored in them.The bytes of a binary file can be characters, or the contents of an executable file.Images, for instance, are stored in binary files.The manipulation of files is more or less independent of its type and involves three stages:Opening the file The operating system reserves some memory for storing of the file s data
[ Pobierz całość w formacie PDF ]