vb程序设计实例

vb程序设计实例,第1张

Private Sub Form_Activate()

'1年期2.25%,2年期2.43%,3年期为2.70%,5年期为2.88%(不记复利)。今有X元,5年以后使用,共有如下6中存法:

Const x1 As Double = 0.0225, x2 As Double = 0.0243, x3 As Double = 0.027, x5 As Double = 0.0288

Dim x As Double

x = Val(InputBox(""))

Print "①存一次5年期,5年后到期的本息合计"ss(x, 5, x5)

Print "②存一次3年期,一次2年期,5年后到期的本息合计"ss(ss(x, 3, x3), 2, x2)

Print "③存一次3年期,两次1年期,5年后到期的本息合计"ss(ss(ss(x, 3, x3), 1, x1), 1, x1)

Print "④存两次2年期,一次1年期,5年后到期的本息合计"ss(ss(ss(x, 2, x2), 2, x2), 1, x1)

Print "⑤存一次2年期,三次1年期,5年后到期的本息合计"ss(ss(ss(ss(x, 2, x2), 1, x1), 1, x1), 1, x1)

Print "⑥存五次1年期,5年后到期的本息合计"ss(ss(ss(ss(ss(x, 1, x1), 1, x1), 1, x1), 1, x1), 1, x1)

End Sub

Private Function ss(ByVal a As Double, b As Integer, c As Double) As Double

ss = a + a * c * b

End Function

Private Sub Form_Load()

AutoRedraw = True

End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = "Form1"

ClientHeight= 3090

ClientLeft = 60

ClientTop = 450

ClientWidth = 4680

LinkTopic = "Form1"

ScaleHeight = 3090

ScaleWidth = 4680

StartUpPosition = 3 '窗口缺省

Begin VB.CommandButton Command1

Caption = "Max!"

Height = 375

Left= 2280

TabIndex= 5

Top = 1680

Width = 975

End

Begin VB.TextBox Text5

Height = 375

Left= 960

TabIndex= 4

Top = 2160

Width = 1215

End

Begin VB.TextBox Text4

Height = 375

Left= 960

TabIndex= 3

Top = 1680

Width = 1215

End

Begin VB.TextBox Text3

Height = 375

Left= 960

TabIndex= 2

Top = 1200

Width = 1215

End

Begin VB.TextBox Text2

Height = 375

Left= 960

TabIndex= 1

Top = 720

Width = 1215

End

Begin VB.TextBox Text1

Height = 375

Left= 960

TabIndex= 0

Top = 240

Width = 1215

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Private Sub Command1_Click()

Dim a(3) As Long

Dim nMax As Long

Dim i As Integer

a(0) = Val(Text1)

a(1) = Val(Text2)

a(2) = Val(Text3)

a(3) = Val(Text4)

nMax = 0

For i = 0 To 3

If nMax <a(i) Then nMax = a(i)

Next

Text5 = nMax

End Sub

把以上存为.frm即可~运行就是了。支持任意多的文本框。

按需要设置7个文本框,输入如下代码:

Private Sub Command1_Click()

Dim sum As Single

sum = Val(Textmath.Text) + Val(Textchina.Text) + Val(Textenglish.Text)

TextAve.Text = sum / 3

Open "d:\data.txt" For Append As #1

Write #1, Textname.Text, TextNo.Text, Textsex.Text, Textmath.Text, Textchina.Text, Textenglish.Text, TextAve.Text

Close

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7830141.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存