大一简单VB编程作业!从键盘输入三门主科成绩,求其平均值

大一简单VB编程作业!从键盘输入三门主科成绩,求其平均值,第1张

你好!

很简单的

添加四个文本框

在form里写衫毁就好了

text1=inputbox("输入分数","成绩")

text2=inputbox("输入分或肢备数","成绩"饥简)

text3=inputbox("输入分数","成绩")

text4=(val(text1)+val(text2)+val(text3))/3

如有疑问,请追问。

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即可~运行就是了。支持任意多的文本框。

Private

Sub

Form_Click()

'注意n的值不能卜贺输入太大卜弊启,太大会出型如现溢出错误

Dim

n

As

Integer,

s

As

Double

n

=

Val(InputBox("n=?"))

s

=

1

For

i

=

1

To

n

s

=

s

*

i

Next

i

MsgBox

"s="

&

s

End

Sub


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存