9189整理新贷款费用估计程序

上传人:w****7 文档编号:147892478 上传时间:2020-10-14 格式:PPT 页数:24 大小:161.51KB
返回 下载 相关 举报
9189整理新贷款费用估计程序_第1页
第1页 / 共24页
9189整理新贷款费用估计程序_第2页
第2页 / 共24页
9189整理新贷款费用估计程序_第3页
第3页 / 共24页
9189整理新贷款费用估计程序_第4页
第4页 / 共24页
9189整理新贷款费用估计程序_第5页
第5页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《9189整理新贷款费用估计程序》由会员分享,可在线阅读,更多相关《9189整理新贷款费用估计程序(24页珍藏版)》请在金锄头文库上搜索。

1、贷款费用估计程序,1.首先创建一个标准工程,并在窗体的属性窗口中将其name属性设为”frmLoad”,Caption属性设为”贷款费用估计”、Font属性设为“宋体、12”。将 StartUpPosition属性设为“2-CenterScreen”,使应用程序居中显示。 2.在窗体上添加与贷款额有关的控件:一个Label控件和一个TextBox控件。并设置它们的属性。,3.接着添加与利率有关的控件:一个Label控件和一个ComboBox控件,并设置它们的属性。 控件 属性 值 Label Name LblRate Caption 利率 ComboBoxName CboRate List 4

2、.5,6.25,7, 8.325,9,10,4.添加与贷款年限有关的控件:一个Frame控件和一个OptionButton控件组,同时设置它们的属性。,控件 属性 值 Frame Name FraTerm Caption 贷款年限 OptionButton Name optLength Caption 10年 Index 0 OptionButton Name optLength Caption 20年 Index 1 OptionButton Name optLength Caption 30年 Index 2,5.再来添加三个CommandButton控件,并设置它们的属性。 控件 属性

3、值CommandButton Namecmd Monthly Caption 月偿还额CommandButton Namecmd Total Caption 偿还总额CommandButton Namecmd Done Caption 关闭 Cancel True,6.请双击“关闭”按钮,在代码窗口中输入语句,该语句将卸载frmLoam窗体。 Private Sub cmdDone_Click() Unload frmLoan End Sub,7.在代码窗口中添加Form_Unload(Cancel As Integer) 事件,并输入需要的代码,该段代码的功能是在退出应用程序之前向用户进行询

4、问,并根据用户的回答执行下一步的操作。 Private Sub Form_Unload(Cancel As Integer) Dim iAnswer As Integer iAnswer = MsgBox(真要退出吗?, vbYesNo) If iAnswer = vbNo Then Cancel = True Else End End If End Sub,8.在开始后面的编程之前,首先在通用声明部分声明一个全局变量mintLength用来表示贷款年限,以及一个全局变量CONV_PERIOD用来表示一年12个月。 Option Explicit Private Const CONV_PERI

5、OD As Integer = 12 Dim mintLength As Integer,9.请双击OptionButton控件,并输入需要的代码语句。,Private Sub optLength_Click(Index As Integer) Select Case Index Case 0 mintLength = 10 Case 1 mintLength = 20 Case 2 mintLength = 30 End Select End Sub,10.首先将光标定位到窗体的代码窗口中,然后打开”工具”菜单,选择”Add Procedure(添加过程)”命令。在出现的对话框中将过程的名称

6、设为“MonthlyPayment“,类型设为”Function“,有效范围设为”Public“,然后单击”OK“。 11.给函数过程添加关键字“As Double”,用来将函数的返回类型设为“Double“ Public Function MonthlyPayment() As Double,12.下面请输入函数的主体内容,该函数先定义了几个变量,然后分别为这几个变量赋值,最后使用VB的Pmt函数计算每月的付款额,并将该数设置为函数的返回值。,Public Function MonthlyPayment() As Double Dim dblMonthRate As Double Dim i

7、ntNumPayments As Integer Dim dblLoanAmt As Double Dim dblRate As Double dblRate = CDbl(cboRate.Text) / 100 dblLoanAmt = CDbl(txtpurchase.Text) intNumPayments = mintLength * CONV_PERIOD dblMonthRate = dblRate / CONV_PERIOD MonthlyPayment = Pmt(Rate:=dblMonthRate, NPer:=intNumPayments, PV:=-dblLoanAmt

8、) End Function,13.请双击窗体上的“月偿还额”按钮。在相应的位置输入代码语句。,Private Sub cmdMonthly_Click() Dim dblMonthly As Double If IsNumeric(txtpurchase.Text) Then Calculate the monthly payment dblMonthly = MonthlyPayment() MsgBox 每月将要还款: & _ Format(dblMonthly, currency) Else MsgBox 贷款额必须为数值 With txtpurchase .SetFocus .Sel

9、Start = 0 .SelLength = Len(.Text) End With End If End Sub,14.运行应用程序,在txtPurchase文本框中输入一个字母,并选择利率和年限,然后单击“月偿还额”按钮,观察结果。再输入一个数值。并选择利率和年限,然后单击“月偿还额”按钮。观察结果,观察完后,退出程序。 15.请在代码窗口中添加From_Load事件,并输入需要的代码。,Private Sub Form_Load() cboRate.Text = 4.5 optLength(0).Value = True optLength_Click 0 End Sub,16.要给工程

10、添加模块,请打开“工程”菜单,选择“添加模块”命令。确认选中“New“选项的”Module“后,单击”打开“按钮。 17.在模块窗口中声明常量,并编写TotalPaid函数。,Const CONV_PERIOD As Integer = 12 Public Function TotalPaid(iLoanLength As Integer) As Double Dim intNumPayments As Integer Dim dblMonthlyPayment As Double error checking for numeric parameter If Not IsNumeric(iL

11、oanLength) Then TotalPaid = 0 Exit Function End If,Calculate the number of payments. use fixed values for now, assume 30 year loan intNumPayments = iLoanLength * CONV_PERIOD calculate total of all payments dblMonthlyPayment = frmLoan.MonthlyPayment() TotalPaid = dblMonthlyPayment * intNumPayments En

12、d Function,18.请双击窗体上的“偿还总额”按钮,并输入需要的代码。 Private Sub cmdTotal_Click() Dim dblTotal As Double If IsNumeric(txtpurchase.Text) Then Calculate the monthly payment dblTotal = TotalPaid(mintLength) MsgBox 偿还总额是 & Format(dblTotal, currency) Else,MsgBox 贷款额必须为数值 With txtpurchase .SetFocus .SelStart = 0 .SelLength = Len(.Text) End With End If End Sub,19.运行应用程序。输入贷款额,再单击“偿还总额”按钮,检验结果。,

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 其它中学文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号